Cataclysm BN
game Class Reference

#include <game.h>

Classes

class  Creature_range
 
class  debug_hour_timer
 
class  draw_callback_t
 
class  monster_range
 
class  non_dead_range
 
class  npc_range
 

Public Types

enum  inventory_item_menu_positon { RIGHT_TERMINAL_EDGE , LEFT_OF_INFO , RIGHT_OF_INFO , LEFT_TERMINAL_EDGE }
 

Public Member Functions

 game ()
 
 ~game ()
 
void load_static_data ()
 Loads static data that does not depend on mods or similar. More...
 
void load_core_data (loading_ui &ui)
 Loads core dynamic data. More...
 
bool is_core_data_loaded () const
 Returns whether the core data is currently loaded. More...
 
bool check_mod_data (const std::vector< mod_id > &opts, loading_ui &ui)
 Check if mods can be successfully loaded. More...
 
void load_world_modfiles (loading_ui &ui)
 Loads core data and mods from the active world. More...
 
std::string get_player_base_save_path () const
 Base path for saving player data. More...
 
std::string get_world_base_save_path () const
 Base path for saving world data. More...
 
bool load_packs (const std::string &msg, const std::vector< mod_id > &packs, loading_ui &ui)
 Load content packs. More...
 
void on_options_changed ()
 Should be invoked whenever options change. More...
 
void setup ()
 
void serialize (std::ostream &fout)
 Saving and loading functions. More...
 
void unserialize (std::istream &fin)
 
void unserialize_master (std::istream &fin)
 
bool dump_stats (const std::string &what, dump_mode mode, const std::vector< std::string > &opts)
 write statistics to stdout and More...
 
bool save ()
 Returns false if saving failed. More...
 
std::vector< std::string > list_active_characters ()
 Returns a list of currently active character saves. More...
 
void write_memorial_file (const std::string &filename, std::string sLastWords)
 Writes information about the character out to a text file timestamped with the time of the file was made. More...
 
bool cleanup_at_end ()
 
void start_calendar ()
 
bool do_turn ()
 MAIN GAME LOOP. More...
 
shared_ptr_fast< ui_adaptorcreate_or_get_main_ui_adaptor ()
 
void invalidate_main_ui_adaptor () const
 
void mark_main_ui_adaptor_resize () const
 
void draw ()
 
void draw_ter (bool draw_sounds=true)
 
void draw_ter (const tripoint &center, bool looking=false, bool draw_sounds=true)
 
void add_draw_callback (shared_ptr_fast< draw_callback_t > cb)
 
void draw_panels (bool force_draw=false)
 
cata::optional< tripointget_veh_dir_indicator_location (bool next) const
 Returns the location where the indicator should go relative to the reality bubble, or nothing to indicate no indicator should be drawn. More...
 
void draw_veh_dir_indicator (bool next)
 
void vertical_move (int z, bool force, bool peeking=false)
 Moves the player vertically. More...
 
void start_hauling (const tripoint &pos)
 
cata::optional< tripointfind_or_make_stairs (map &mp, int z_after, bool &rope_ladder, bool peeking)
 Returns the other end of the stairs (if any). More...
 
void vertical_shift (int z_after)
 Actual z-level movement part of vertical_move. More...
 
void vertical_notes (int z_before, int z_after)
 Add goes up/down auto_notes (if turned on) More...
 
void use_computer (const tripoint &p)
 Checks to see if a player can use a computer (not illiterate, etc.) and uses if able. More...
 
template<typename T = Creature>
T * critter_by_id (const character_id &id)
 
template<typename T = Creature>
T * critter_at (const tripoint &p, bool allow_hallucination=false)
 Returns the Creature at the given location. More...
 
template<typename T = Creature>
const T * critter_at (const tripoint &p, bool allow_hallucination=false) const
 
template<typename T = Creature>
shared_ptr_fast< T > shared_from (const T &critter)
 Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature). More...
 
size_t num_creatures () const
 Returns the approximate number of creatures in the reality bubble. More...
 
bool update_zombie_pos (const monster &critter, const tripoint &pos)
 Redirects to the creature_tracker update_pos() function. More...
 
void remove_zombie (const monster &critter)
 
void clear_zombies ()
 Redirects to the creature_tracker clear() function. More...
 
bool spawn_hallucination (const tripoint &p)
 Spawns a hallucination at a determined position. More...
 
bool swap_critters (Creature &, Creature &)
 Swaps positions of two creatures. More...
 
Creature_range all_creatures ()
 Returns an anonymous range that contains all creatures. More...
 
monster_range all_monsters ()
 Same as all_creatures but iterators only over monsters. More...
 
npc_range all_npcs ()
 Same as all_creatures but iterators only over npcs. More...
 
std::vector< Creature * > get_creatures_if (const std::function< bool(const Creature &)> &pred)
 Returns all creatures matching a predicate. More...
 
std::vector< npc * > get_npcs_if (const std::function< bool(const npc &)> &pred)
 
Creatureget_creature_if (const std::function< bool(const Creature &)> &pred)
 Returns a creature matching a predicate. More...
 
bool is_empty (const tripoint &p)
 Returns true if there is no player, NPC, or monster on the tile and move_cost > 0. More...
 
bool is_in_sunlight (const tripoint &p)
 Returns true if p is outdoors and it is sunny. More...
 
bool is_sheltered (const tripoint &p)
 Returns true if p is indoors, underground, or in a car. More...
 
bool revive_corpse (const tripoint &p, item &it)
 Revives a corpse at given location. More...
 
void save_cyborg (item *cyborg, const tripoint &couch_pos, player &installer)
 Turns Broken Cyborg monster into Cyborg NPC via surgery. More...
 
bool cancel_activity_query (const std::string &text)
 Asks if the player wants to cancel their activity, and if so cancels it. More...
 
bool cancel_activity_or_ignore_query (distraction_type type, const std::string &text)
 Asks if the player wants to cancel their activity and if so cancels it. More...
 
void moving_vehicle_dismount (const tripoint &dest_loc)
 Handles players exiting from moving vehicles. More...
 
vehicleremoteveh ()
 Returns the current remotely controlled vehicle. More...
 
void setremoteveh (vehicle *veh)
 Sets the current remotely controlled vehicle. More...
 
int assign_mission_id ()
 Returns the next available mission id. More...
 
npcfind_npc (character_id id)
 Find the npc with the given ID. More...
 
void load_npcs ()
 Makes any nearby NPCs on the overmap active. More...
 
void reload_npcs ()
 Unloads, then loads the NPCs. More...
 
const kill_trackerget_kill_tracker () const
 
void add_npc_follower (const character_id &id)
 Add follower id to set of followers. More...
 
void remove_npc_follower (const character_id &id)
 Remove follower id from follower set. More...
 
std::set< character_idget_follower_list ()
 Get set of followers. More...
 
void validate_npc_followers ()
 validate list of followers to account for overmap buffers More...
 
void validate_mounted_npcs ()
 
void validate_linked_vehicles ()
 validate towed vehicles so they get linked up again after a load More...
 
void validate_camps ()
 validate camps to ensure they are on the overmap list More...
 
void autopilot_vehicles ()
 process vehicles that are following the player More...
 
void catch_a_monster (monster *fish, const tripoint &pos, player *p, const time_duration &catch_duration)
 Picks and spawns a random fish from the remaining fish list when a fish is caught. More...
 
std::unordered_set< tripointget_fishable_locations (int distance, const tripoint &fish_pos)
 Get the contiguous fishable locations starting at fish_pos, out to the specificed distance. More...
 
std::vector< monster * > get_fishable_monsters (std::unordered_set< tripoint > &fishable_locations)
 Get the fishable monsters within the provided fishable locations. More...
 
void fling_creature (Creature *c, const units::angle &dir, float flvel, bool controlled=false, bool suppress_map_update=false)
 Flings the input creature in the given direction. More...
 
float natural_light_level (int zlev) const
 
unsigned char light_level (int zlev) const
 Returns coarse number-of-squares of visibility at the current light level. More...
 
void reset_light_level ()
 
character_id assign_npc_id ()
 
Creatureis_hostile_nearby ()
 
Creatureis_hostile_very_close ()
 
point update_map (player &p)
 
point update_map (int &x, int &y)
 
void update_overmap_seen ()
 
void process_artifact (item &it, player &p)
 
void add_artifact_messages (const std::vector< art_effect_passive > &effects)
 
void add_artifact_dreams ()
 
void peek ()
 
void peek (const tripoint &p)
 
cata::optional< tripointlook_debug ()
 
bool check_zone (const zone_type_id &type, const tripoint &where) const
 
bool check_near_zone (const zone_type_id &type, const tripoint &where) const
 Checks whether or not there is a zone of particular type nearby. More...
 
bool is_zones_manager_open () const
 
void zones_manager ()
 
cata::optional< tripointlook_around ()
 
look_around_result look_around (bool show_window, tripoint &center, const tripoint &start_point, bool has_first_point, bool select_zone, bool peeking, bool is_moving_zone=false, const tripoint &end_point=tripoint_zero)
 
void pre_print_all_tile_info (const tripoint &lp, const catacurses::window &w_info, int &line, int last_line, const visibility_variables &cache)
 
void print_all_tile_info (const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line, int last_line, const visibility_variables &cache)
 
void draw_look_around_cursor (const tripoint &lp, const visibility_variables &cache)
 
void extended_description (const tripoint &p)
 Long description of (visible) things at tile. More...
 
void draw_trail_to_square (const tripoint &t, bool bDrawX)
 
int inventory_item_menu (item_location locThisItem, const std::function< int()> &startx=[]() { return 0;}, const std::function< int()> &width=[]() { return 50;}, inventory_item_menu_positon position=RIGHT_OF_INFO)
 
item_location inv_map_splice (item_filter filter, const std::string &title, int radius=0, const std::string &none_message="")
 Custom-filtered menu for inventory and nearby items and those that within specified radius. More...
 
bool has_gametype () const
 
special_game_id gametype () const
 
void toggle_fullscreen ()
 
void toggle_pixel_minimap ()
 
void reload_tileset ()
 
void temp_exit_fullscreen ()
 
void reenter_fullscreen ()
 
void zoom_in ()
 
void zoom_out ()
 
void reset_zoom ()
 
void set_zoom (int level)
 
int get_zoom () const
 
int get_moves_since_last_save () const
 
int get_user_action_counter () const
 
bool take_screenshot (const std::string &file_path) const
 Saves a screenshot of the current viewport, as a PNG file, to the given location. More...
 
bool take_screenshot () const
 Saves a screenshot of the current viewport, as a PNG file. More...
 
int get_levx () const
 The top left corner of the reality bubble (in submaps coordinates). More...
 
int get_levy () const
 
int get_levz () const
 
void load_map (const tripoint &pos_sm)
 Load the main map at given location, see map::load, in global, absolute submap coordinates. More...
 
void load_map (const tripoint_abs_sm &pos_sm)
 
overmapget_cur_om () const
 The overmap which contains the center submap of the reality bubble. More...
 
std::vector< npc * > allies ()
 Get all living player allies. More...
 
void set_driving_view_offset (const point &p)
 
void calc_driving_offset (vehicle *veh=nullptr)
 
void open_gate (const tripoint &p)
 
void knockback (const tripoint &s, const tripoint &t, int force, int stun, int dam_mult)
 
void knockback (std::vector< tripoint > &traj, int stun, int dam_mult)
 
void draw_bullet (const tripoint &t, int i, const std::vector< tripoint > &trajectory, char bullet)
 
void draw_hit_mon (const tripoint &p, const monster &m, bool dead=false)
 
void draw_hit_player (const Character &p, int dam)
 
void draw_line (const tripoint &p, const tripoint &center_point, const std::vector< tripoint > &points, bool noreveal=false)
 
void draw_line (const tripoint &p, const std::vector< tripoint > &points)
 
void draw_weather (const weather_printable &wPrint)
 
void draw_sct ()
 
void draw_zones (const tripoint &start, const tripoint &end, const tripoint &offset)
 
void draw_critter (const Creature &critter, const tripoint &center)
 
void draw_critter_highlighted (const Creature &critter, const tripoint &center)
 
void draw_cursor (const tripoint &p)
 
void draw_highlight (const tripoint &p)
 
void draw_radiation_override (const tripoint &p, int rad)
 
void draw_terrain_override (const tripoint &p, const ter_id &id)
 
void draw_furniture_override (const tripoint &p, const furn_id &id)
 
void draw_graffiti_override (const tripoint &p, bool has)
 
void draw_trap_override (const tripoint &p, const trap_id &id)
 
void draw_field_override (const tripoint &p, const field_type_id &id)
 
void draw_item_override (const tripoint &p, const itype_id &id, const mtype_id &mid, bool hilite)
 
void draw_vpart_override (const tripoint &p, const vpart_id &id, int part_mod, units::angle veh_dir, bool hilite, const point &mount)
 
void draw_below_override (const tripoint &p, bool draw)
 
void draw_monster_override (const tripoint &p, const mtype_id &id, int count, bool more, Creature::Attitude att)
 
bool is_in_viewport (const tripoint &p, int margin=0) const
 
bool check_safe_mode_allowed (bool repeat_safe_mode_warnings=true)
 Check whether movement is allowed according to safe mode settings. More...
 
void set_safe_mode (safe_mode_type mode)
 
void exam_vehicle (vehicle &veh, const point &cp=point_zero)
 open vehicle interaction screen More...
 
bool forced_door_closing (const tripoint &p, const ter_id &door_type, int bash_dmg)
 
bool load (const std::string &world)
 Attempt to load first valid save (if any) in world. More...
 
bool npc_menu (npc &who)
 Returns true if the menu handled stuff and player shouldn't do anything else. More...
 
bool phasing_move (const tripoint &dest, bool via_ramp=false)
 
bool walk_move (const tripoint &dest, bool via_ramp=false)
 
void on_move_effects ()
 
void reload (item_location &loc, bool prompt=false, bool empty=true)
 
void reload_item ()
 
void reload_wielded (bool prompt=false)
 
void reload_weapon (bool try_everything=true)
 
point place_player (const tripoint &dest)
 
void place_player_overmap (const tripoint_abs_omt &om_dest)
 
bool unload (item_location loc)
 
unsigned int get_seed () const
 
void set_npcs_dirty ()
 If invoked, NPCs will be reloaded before next turn. More...
 
void set_critter_died ()
 If invoked, dead will be cleaned this turn. More...
 
void mon_info (const catacurses::window &, int hor_padding=0)
 
void mon_info_update ()
 
void cleanup_dead ()
 
bool is_dangerous_tile (const tripoint &dest_loc) const
 
std::vector< std::string > get_dangerous_tile (const tripoint &dest_loc) const
 
bool prompt_dangerous_tile (const tripoint &dest_loc) const
 
void despawn_monster (monster &critter)
 Despawn a specific monster, it's stored on the overmap. More...
 
void win ()
 Marks the game as won. More...
 
bool disable_robot (const tripoint &p)
 If there is a robot (that can be disabled), query the player and try to disable it. More...
 
void draw_pixel_minimap (const catacurses::window &w)
 
void quicksave ()
 
void disp_NPCs ()
 
void list_missions ()
 
event_busevents ()
 
stats_trackerstats ()
 
memorial_loggermemorial ()
 
spell_eventsspell_events_subscriber ()
 
void display_toggle_overlay (action_id)
 
bool display_overlay_state (action_id)
 
void toggle_debug_hour_timer ()
 
tripoint mouse_edge_scrolling_terrain (input_context &ctxt)
 Used to implement mouse "edge scrolling". More...
 
tripoint mouse_edge_scrolling_overmap (input_context &ctxt)
 This variant is suitable for the overmap. More...
 
void shift_destination_preview (const point &delta)
 
bool slip_down ()
 Checks if player is able to successfully climb to/from some terrain and not slip down. More...
 
monsterplace_critter_at (const mtype_id &id, const tripoint &p)
 Adds critters to the reality bubble, creating them if necessary. More...
 
monsterplace_critter_at (const shared_ptr_fast< monster > &mon, const tripoint &p)
 
monsterplace_critter_around (const mtype_id &id, const tripoint &center, int radius)
 
monsterplace_critter_around (const shared_ptr_fast< monster > &mon, const tripoint &center, int radius, bool forced=false)
 
monsterplace_critter_within (const mtype_id &id, const tripoint_range< tripoint > &range)
 
monsterplace_critter_within (const shared_ptr_fast< monster > &mon, const tripoint_range< tripoint > &range)
 

Public Attributes

mapm
 
avataru
 
scent_mapscent
 
timed_event_managertimed_events
 
pimpl< Creature_trackercritter_tracker
 
pimpl< faction_managerfaction_manager_ptr
 
pimpl< drop_token_providertoken_provider_ptr
 
quit_status uquit
 Used in main.cpp to determine what type of quit is being performed. More...
 
bool new_game = false
 True if the game has just started or loaded, else false. More...
 
const scenarioscen
 
std::vector< monstercoming_to_stairs
 
int monstairz = 0
 
tripoint ter_view_p
 
catacurses::window w_terrain
 
catacurses::window w_overmap
 
catacurses::window w_omlegend
 
catacurses::window w_minimap
 
catacurses::window w_pixel_minimap
 
point driving_view_offset
 
bool debug_pathfinding = false
 
bool debug_submap_grid_overlay = false
 
Creaturedisplaying_visibility_creature
 Creature for which to display the visibility map. More...
 
int displaying_lighting_condition = 0
 Type of lighting condition overlay to display. More...
 
bool show_panel_adm = false
 
bool right_sidebar = false
 
bool fullscreen = false
 
bool was_fullscreen = false
 
bool auto_travel_mode = false
 
bool queue_screenshot = false
 
safe_mode_type safe_mode
 
int turnssincelastmon = 0
 
int mostseen = 0
 

Protected Member Functions

void load_data_from_dir (const std::string &path, const std::string &src, loading_ui &ui)
 Loads dynamic data from the given directory. More...
 

Private Types

enum class  vmenu_ret : int { CHANGE_TAB , QUIT , FIRE }
 

Private Member Functions

void unload_npcs ()
 Unloads all NPCs. More...
 
bool load (const save_t &name)
 
void load_master ()
 
bool start_game ()
 
bool save_factions_missions_npcs ()
 
void reset_npc_dispositions ()
 
void serialize_master (std::ostream &fout)
 
bool save_artifacts ()
 
bool save_maps ()
 
void init_autosave ()
 
void create_starting_npcs ()
 
vehicleplace_vehicle_nearby (const vproto_id &id, const point_abs_omt &origin, int min_distance, int max_distance, const std::vector< std::string > &omt_search_types={})
 
void list_items_monsters ()
 
game::vmenu_ret list_items (const std::vector< map_item_stack > &item_list)
 
std::vector< map_item_stackfind_nearby_items (int iRadius)
 
void reset_item_list_state (const catacurses::window &window, int height, bool bRadiusSort)
 
game::vmenu_ret list_monsters (const std::vector< Creature * > &monster_list)
 
bool grabbed_move (const tripoint &dp)
 Check for dangerous stuff at dest_loc, return false if the player decides not to step there. More...
 
bool grabbed_veh_move (const tripoint &dp)
 
bool grabbed_furn_move (const tripoint &dp)
 
void control_vehicle ()
 
void examine (const tripoint &p)
 
void examine ()
 
void pickup ()
 
void pickup (const tripoint &p)
 
void pickup_feet ()
 
void drop ()
 
void drop_in_direction ()
 
void butcher ()
 
void wield ()
 
void wield (item_location &loc)
 
void chat ()
 
void print_fields_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line)
 
void print_terrain_info (const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line)
 
void print_trap_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line)
 
void print_creature_info (const Creature *creature, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_vehicle_info (const vehicle *veh, int veh_part, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_visibility_info (const catacurses::window &w_look, int column, int &line, visibility_type visibility)
 
void print_items_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_graffiti_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
 
input_context get_player_input (std::string &action)
 
void replace_stair_monsters ()
 
void update_stair_monsters ()
 
void shift_monsters (const tripoint &shift)
 Shift all active monsters, the shift vector is the number of shifted submaps. More...
 
void perhaps_add_random_npc ()
 
void monmove ()
 
void overmap_npc_move ()
 
void process_voluntary_act_interrupt ()
 
void process_activity ()
 
void handle_key_blocking_activity ()
 
void open_consume_item_menu ()
 
bool handle_action ()
 
bool try_get_right_click_action (action_id &act, const tripoint &mouse_target)
 
bool try_get_left_click_action (action_id &act, const tripoint &mouse_target)
 
void item_action_menu ()
 
bool is_game_over ()
 
void death_screen ()
 
void win_screen ()
 
void draw_minimap ()
 
void autosave ()
 
void quickload ()
 
bool handle_mouseview (input_context &ctxt, std::string &action)
 
void display_faction_epilogues ()
 
void disp_NPC_epilogues ()
 
void display_scent ()
 
void display_temperature ()
 
void display_vehicle_ai ()
 
void display_visibility ()
 
void display_lighting ()
 
void display_radiation ()
 
void display_transparency ()
 
Creatureis_hostile_within (int distance)
 
void move_save_to_graveyard (const std::string &dirname)
 
bool save_player_data ()
 
std::pair< tripoint, tripointmouse_edge_scrolling (input_context &ctxt, int speed, const tripoint &last, bool iso)
 

Private Attributes

bool is_looking = false
 
std::vector< weak_ptr_fast< draw_callback_t > > draw_callbacks
 
cata::optional< action_iddisplaying_overlays
 
class game::debug_hour_timer debug_hour_timer
 
pimpl< mapmap_ptr
 
pimpl< avataru_ptr
 
pimpl< live_viewliveview_ptr
 
live_viewliveview
 
pimpl< scent_mapscent_ptr
 
pimpl< timed_event_managertimed_event_manager_ptr
 
pimpl< event_busevent_bus_ptr
 
pimpl< stats_trackerstats_tracker_ptr
 
pimpl< achievements_trackerachievements_tracker_ptr
 
pimpl< kill_trackerkill_tracker_ptr
 
pimpl< memorial_loggermemorial_logger_ptr
 
pimpl< spell_eventsspell_events_ptr
 
pimpl< distribution_grid_trackergrid_tracker_ptr
 
pimpl< weather_managerweather_manager_ptr
 
shared_ptr_fast< playeru_shared_ptr
 
catacurses::window w_terrain_ptr
 
catacurses::window w_minimap_ptr
 
std::string sFilter
 
std::string list_item_upvote
 
std::string list_item_downvote
 
bool safe_mode_warning_logged = false
 
bool bVMonsterLookFire = false
 
character_id next_npc_id
 
std::list< shared_ptr_fast< npc > > active_npc
 
int next_mission_id = 0
 
std::set< character_idfollower_ids
 
int moves_since_last_save = 0
 
time_t last_save_timestamp
 
std::array< float, OVERMAP_LAYERSlatest_lightlevels
 
time_point remoteveh_cache_time
 
vehicleremoteveh_cache
 
bool npcs_dirty = false
 Has a NPC been spawned since last load? More...
 
bool critter_died = false
 Has anything died in this turn and needs to be cleaned up? More...
 
bool first_redraw_since_waiting_started = true
 Is this the first redraw since waiting (sleeping or activity) started. More...
 
bool zones_manager_open = false
 Is Zone manager open or not - changes graphics of some zone tiles. More...
 
std::unique_ptr< special_gamegamemode
 
int user_action_counter = 0
 
int tileset_zoom = 0
 How far the tileset should be zoomed out, 16 is default. More...
 
unsigned int seed = 0
 Seed for all the random numbers that should have consistent randomness (weather). More...
 
std::vector< tripointdestination_preview
 
std::chrono::time_point< std::chrono::steady_clock > last_mouse_edge_scroll
 
tripoint last_mouse_edge_scroll_vector_terrain
 
tripoint last_mouse_edge_scroll_vector_overmap
 
weak_ptr_fast< ui_adaptormain_ui_adaptor
 
std::unique_ptr< static_popupwait_popup
 

Friends

class editmap
 
class advanced_inventory
 
class main_menu
 
class monster_range
 
class Creature_range
 
distribution_grid_trackerget_distribution_grid_tracker ()
 Returns distribution grid tracker that is a part of the global game *g. More...
 
mapget_map ()
 
Characterget_player_character ()
 
avatarget_avatar ()
 
weather_managerget_weather ()
 

Detailed Description

Definition at line 143 of file game.h.

Member Enumeration Documentation

◆ inventory_item_menu_positon

Enumerator
RIGHT_TERMINAL_EDGE 
LEFT_OF_INFO 
RIGHT_OF_INFO 
LEFT_TERMINAL_EDGE 

Definition at line 611 of file game.h.

611 {
616 };
@ LEFT_OF_INFO
Definition: game.h:613
@ RIGHT_OF_INFO
Definition: game.h:614
@ RIGHT_TERMINAL_EDGE
Definition: game.h:612
@ LEFT_TERMINAL_EDGE
Definition: game.h:615

◆ vmenu_ret

enum class game::vmenu_ret : int
strongprivate
Enumerator
CHANGE_TAB 
QUIT 
FIRE 

Definition at line 805 of file game.h.

805 : int {
806 CHANGE_TAB,
807 QUIT,
808 FIRE, // Who knew, apparently you can do that in list_monsters
809 };

Constructor & Destructor Documentation

◆ game()

game::game ( )

Definition at line 283 of file game.cpp.

283 :
285 scent_ptr( *this ),
288 m( *map_ptr ),
289 u( *u_ptr ),
290 scent( *scent_ptr ),
292 uquit( QUIT_NO ),
293 new_game( false ),
295 mostseen( 0 ),
298 next_npc_id( 1 ),
299 next_mission_id( 1 ),
303 seed( 0 ),
304 last_mouse_edge_scroll( std::chrono::steady_clock::now() )
305{
313 world_generator = std::make_unique<worldfactory>();
314 // do nothing, everything that was in here is moved to init_data() which is called immediately after g = new game; in main.cpp
315 // The reason for this move is so that g is not uninitialized when it gets to installing the parts into vehicles.
316}
void subscribe(event_subscriber *)
Definition: event_bus.cpp:39
int mostseen
Definition: game.h:1071
pimpl< spell_events > spell_events_ptr
Definition: game.h:1006
safe_mode_type safe_mode
Definition: game.h:1068
bool safe_mode_warning_logged
Definition: game.h:1082
pimpl< timed_event_manager > timed_event_manager_ptr
Definition: game.h:1000
std::chrono::time_point< std::chrono::steady_clock > last_mouse_edge_scroll
Definition: game.h:1116
quit_status uquit
Used in main.cpp to determine what type of quit is being performed.
Definition: game.h:1026
event_bus & events()
Definition: game.cpp:3075
pimpl< stats_tracker > stats_tracker_ptr
Definition: game.h:1002
character_id next_npc_id
Definition: game.h:1084
pimpl< kill_tracker > kill_tracker_ptr
Definition: game.h:1004
void reset_light_level()
Definition: game.cpp:3919
pimpl< memorial_logger > memorial_logger_ptr
Definition: game.h:1005
shared_ptr_fast< player > u_shared_ptr
Definition: game.h:1073
pimpl< map > map_ptr
Definition: game.h:995
bool first_redraw_since_waiting_started
Is this the first redraw since waiting (sleeping or activity) started.
Definition: game.h:1099
pimpl< live_view > liveview_ptr
Definition: game.h:997
pimpl< achievements_tracker > achievements_tracker_ptr
Definition: game.h:1003
pimpl< scent_map > scent_ptr
Definition: game.h:999
timed_event_manager & timed_events
Definition: game.h:1014
unsigned int seed
Seed for all the random numbers that should have consistent randomness (weather).
Definition: game.h:1111
int next_mission_id
Definition: game.h:1086
bool new_game
True if the game has just started or loaded, else false.
Definition: game.h:1028
pimpl< distribution_grid_tracker > grid_tracker_ptr
Definition: game.h:1007
map & m
Definition: game.h:1011
avatar & u
Definition: game.h:1012
scent_map & scent
Definition: game.h:1013
int user_action_counter
Definition: game.h:1105
live_view & liveview
Definition: game.h:998
int tileset_zoom
How far the tileset should be zoomed out, 16 is default.
Definition: game.h:1108
pimpl< avatar > u_ptr
Definition: game.h:996
time_point remoteveh_cache_time
Definition: game.h:1092
static void achievement_attained(const achievement *a)
Definition: game.cpp:276
static constexpr int DEFAULT_TILESET_ZOOM
Definition: game.h:41
@ SAFE_MODE_ON
Definition: game.h:78
@ QUIT_NO
Definition: game.h:68
mapbuffer MAPBUFFER
Definition: mapbuffer.cpp:40
const time_point before_time_starts
A time point that is always before the current turn, even when the game has just started.
Definition: calendar.cpp:25
For use with smart pointers when you don't actually want the deleter to do anything.
Definition: cata_utility.h:28
std::unique_ptr< worldfactory > world_generator

References achievements_tracker_ptr, events(), first_redraw_since_waiting_started, kill_tracker_ptr, memorial_logger_ptr, reset_light_level(), spell_events_ptr, stats_tracker_ptr, event_bus::subscribe(), and world_generator.

◆ ~game()

game::~game ( )
default

Member Function Documentation

◆ add_artifact_dreams()

void game::add_artifact_dreams ( )

Definition at line 12345 of file game.cpp.

12346{
12347 //If player is sleeping, get a dream from a carried artifact
12348 //Don't need to check that player is sleeping here, that's done before calling
12349 std::list<item *> art_items = g->u.get_artifact_items();
12350 std::vector<item *> valid_arts;
12351 std::vector<std::vector<std::string>>
12352 valid_dreams; // Tracking separately so we only need to check its req once
12353 //Pull the list of dreams
12354 add_msg( m_debug, "Checking %s carried artifacts", art_items.size() );
12355 for( auto &it : art_items ) {
12356 //Pick only the ones with an applicable dream
12357 const cata::value_ptr<islot_artifact> &art = it->type->artifact;
12358 if( art && art->charge_req != ACR_NULL &&
12359 ( it->ammo_remaining() < it->ammo_capacity() ||
12360 it->ammo_capacity() == 0 ) ) { //or max 0 in case of wacky mod shenanigans
12361 add_msg( m_debug, "Checking artifact %s", it->tname() );
12362 if( check_art_charge_req( *it ) ) {
12363 add_msg( m_debug, " Has freq %s,%s", art->dream_freq_met, art->dream_freq_unmet );
12364 if( art->dream_freq_met > 0 && x_in_y( art->dream_freq_met, 100 ) ) {
12365 add_msg( m_debug, "Adding met dream from %s", it->tname() );
12366 valid_arts.push_back( it );
12367 valid_dreams.push_back( art->dream_msg_met );
12368 }
12369 } else {
12370 add_msg( m_debug, " Has freq %s,%s", art->dream_freq_met, art->dream_freq_unmet );
12371 if( art->dream_freq_unmet > 0 && x_in_y( art->dream_freq_unmet, 100 ) ) {
12372 add_msg( m_debug, "Adding unmet dream from %s", it->tname() );
12373 valid_arts.push_back( it );
12374 valid_dreams.push_back( art->dream_msg_unmet );
12375 }
12376 }
12377 }
12378 }
12379 if( !valid_dreams.empty() ) {
12380 add_msg( m_debug, "Found %s valid artifact dreams", valid_dreams.size() );
12381 const int selected = rng( 0, valid_arts.size() - 1 );
12382 auto it = valid_arts[selected];
12383 auto msg = random_entry( valid_dreams[selected] );
12384 const std::string &dream = string_format( _( msg ), it->tname() );
12385 add_msg( dream );
12386 } else {
12387 add_msg( m_debug, "Didn't have any dreams, sorry" );
12388 }
12389}
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
@ ACR_NULL
Definition: artifact.h:79
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
@ m_debug
Definition: enums.h:264
std::unique_ptr< game > g
Definition: game.cpp:266
bool check_art_charge_req(item &it)
Definition: game.cpp:12049
void add_msg(std::string msg)
Definition: messages.cpp:884
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88
std::string string_format(std::string format, Args &&...args)
Simple wrapper over string_formatter::parse.
Definition: mutation.h:39
#define _(msg)
Definition: translations.h:116

References _, ACR_NULL, add_msg(), check_art_charge_req(), g, m_debug, random_entry(), rng(), string_format(), and x_in_y().

Referenced by do_turn().

◆ add_artifact_messages()

void game::add_artifact_messages ( const std::vector< art_effect_passive > &  effects)

Definition at line 12167 of file game.cpp.

12168{
12169 int net_str = 0;
12170 int net_dex = 0;
12171 int net_per = 0;
12172 int net_int = 0;
12173 int net_speed = 0;
12174
12175 for( auto &i : effects ) {
12176 switch( i ) {
12177 case AEP_STR_UP:
12178 net_str += 4;
12179 break;
12180 case AEP_DEX_UP:
12181 net_dex += 4;
12182 break;
12183 case AEP_PER_UP:
12184 net_per += 4;
12185 break;
12186 case AEP_INT_UP:
12187 net_int += 4;
12188 break;
12189 case AEP_ALL_UP:
12190 net_str += 2;
12191 net_dex += 2;
12192 net_per += 2;
12193 net_int += 2;
12194 break;
12195 case AEP_STR_DOWN:
12196 net_str -= 3;
12197 break;
12198 case AEP_DEX_DOWN:
12199 net_dex -= 3;
12200 break;
12201 case AEP_PER_DOWN:
12202 net_per -= 3;
12203 break;
12204 case AEP_INT_DOWN:
12205 net_int -= 3;
12206 break;
12207 case AEP_ALL_DOWN:
12208 net_str -= 2;
12209 net_dex -= 2;
12210 net_per -= 2;
12211 net_int -= 2;
12212 break;
12213
12214 case AEP_SPEED_UP:
12215 net_speed += 20;
12216 break;
12217 case AEP_SPEED_DOWN:
12218 net_speed -= 20;
12219 break;
12220
12221 case AEP_PBLUE:
12222 break; // No message
12223
12224 case AEP_SNAKES:
12225 add_msg( m_warning, _( "Your skin feels slithery." ) );
12226 break;
12227
12228 case AEP_INVISIBLE:
12229 add_msg( m_good, _( "You fade into invisibility!" ) );
12230 break;
12231
12232 case AEP_CLAIRVOYANCE:
12234 add_msg( m_good, _( "You can see through walls!" ) );
12235 break;
12236
12238 add_msg( m_good, _( "You can see through everything!" ) );
12239 break;
12240
12241 case AEP_STEALTH:
12242 add_msg( m_good, _( "Your steps stop making noise." ) );
12243 break;
12244
12245 case AEP_GLOW:
12246 add_msg( _( "A glow of light forms around you." ) );
12247 break;
12248
12249 case AEP_PSYSHIELD:
12250 add_msg( m_good, _( "Your mental state feels protected." ) );
12251 break;
12252
12254 add_msg( m_good, _( "You feel insulated." ) );
12255 break;
12256
12257 case AEP_CARRY_MORE:
12258 add_msg( m_good, _( "Your back feels strengthened." ) );
12259 break;
12260
12261 case AEP_FUN:
12262 add_msg( m_good, _( "You feel a pleasant tingle." ) );
12263 break;
12264
12265 case AEP_HUNGER:
12266 add_msg( m_warning, _( "You feel hungry." ) );
12267 break;
12268
12269 case AEP_THIRST:
12270 add_msg( m_warning, _( "You feel thirsty." ) );
12271 break;
12272
12273 case AEP_EVIL:
12274 add_msg( m_warning, _( "You feel an evil presence…" ) );
12275 break;
12276
12277 case AEP_SCHIZO:
12278 add_msg( m_bad, _( "You feel a tickle of insanity." ) );
12279 break;
12280
12281 case AEP_RADIOACTIVE:
12282 add_msg( m_warning, _( "Your skin prickles with radiation." ) );
12283 break;
12284
12285 case AEP_MUTAGENIC:
12286 add_msg( m_bad, _( "You feel your genetic makeup degrading." ) );
12287 break;
12288
12289 case AEP_ATTENTION:
12290 add_msg( m_warning, _( "You feel an otherworldly attention upon you…" ) );
12291 break;
12292
12293 case AEP_FORCE_TELEPORT:
12294 add_msg( m_bad, _( "You feel a force pulling you inwards." ) );
12295 break;
12296
12297 case AEP_MOVEMENT_NOISE:
12298 add_msg( m_warning, _( "You hear a rattling noise coming from inside yourself." ) );
12299 break;
12300
12301 case AEP_BAD_WEATHER:
12302 add_msg( m_warning, _( "You feel storms coming." ) );
12303 break;
12304
12305 case AEP_SICK:
12306 add_msg( m_bad, _( "You feel unwell." ) );
12307 break;
12308
12309 case AEP_SMOKE:
12310 add_msg( m_warning, _( "A cloud of smoke appears." ) );
12311 break;
12312 default:
12313 //Suppress warnings
12314 break;
12315 }
12316 }
12317
12318 std::string stat_info;
12319 if( net_str != 0 ) {
12320 stat_info += string_format( _( "Str %s%d! " ),
12321 ( net_str > 0 ? "+" : "" ), net_str );
12322 }
12323 if( net_dex != 0 ) {
12324 stat_info += string_format( _( "Dex %s%d! " ),
12325 ( net_dex > 0 ? "+" : "" ), net_dex );
12326 }
12327 if( net_int != 0 ) {
12328 stat_info += string_format( _( "Int %s%d! " ),
12329 ( net_int > 0 ? "+" : "" ), net_int );
12330 }
12331 if( net_per != 0 ) {
12332 stat_info += string_format( _( "Per %s%d! " ),
12333 ( net_per > 0 ? "+" : "" ), net_per );
12334 }
12335
12336 if( !stat_info.empty() ) {
12337 add_msg( m_neutral, stat_info );
12338 }
12339
12340 if( net_speed != 0 ) {
12341 add_msg( m_info, _( "Speed %s%d!" ), ( net_speed > 0 ? "+" : "" ), net_speed );
12342 }
12343}
@ m_good
Definition: enums.h:253
@ m_neutral
Definition: enums.h:260
@ m_info
Definition: enums.h:258
@ m_bad
Definition: enums.h:254
@ m_warning
Definition: enums.h:257
@ AEP_GLOW
Definition: enums.h:115
@ AEP_MUTAGENIC
Definition: enums.h:130
@ AEP_ALL_UP
Definition: enums.h:106
@ AEP_INT_UP
Definition: enums.h:105
@ AEP_INT_DOWN
Definition: enums.h:135
@ AEP_PER_UP
Definition: enums.h:104
@ AEP_PSYSHIELD
Definition: enums.h:116
@ AEP_CLAIRVOYANCE_PLUS
Definition: enums.h:142
@ AEP_MOVEMENT_NOISE
Definition: enums.h:139
@ AEP_STEALTH
Definition: enums.h:113
@ AEP_CARRY_MORE
Definition: enums.h:118
@ AEP_THIRST
Definition: enums.h:125
@ AEP_SPEED_UP
Definition: enums.h:107
@ AEP_EVIL
Definition: enums.h:127
@ AEP_ALL_DOWN
Definition: enums.h:136
@ AEP_DEX_UP
Definition: enums.h:103
@ AEP_SCHIZO
Definition: enums.h:128
@ AEP_DEX_DOWN
Definition: enums.h:133
@ AEP_FUN
Definition: enums.h:120
@ AEP_PER_DOWN
Definition: enums.h:134
@ AEP_FORCE_TELEPORT
Definition: enums.h:138
@ AEP_ATTENTION
Definition: enums.h:131
@ AEP_RADIOACTIVE
Definition: enums.h:129
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
@ AEP_BAD_WEATHER
Definition: enums.h:140
@ AEP_SICK
Definition: enums.h:141
@ AEP_CLAIRVOYANCE
Definition: enums.h:111
@ AEP_INVISIBLE
Definition: enums.h:110
@ AEP_STR_UP
Definition: enums.h:102
@ AEP_STR_DOWN
Definition: enums.h:132
@ AEP_HUNGER
Definition: enums.h:124
@ AEP_RESIST_ELECTRICITY
Definition: enums.h:117
@ AEP_PBLUE
Definition: enums.h:108
@ AEP_SPEED_DOWN
Definition: enums.h:137
@ AEP_SNAKES
Definition: enums.h:109
@ AEP_SMOKE
Definition: enums.h:126

References _, add_msg(), AEP_ALL_DOWN, AEP_ALL_UP, AEP_ATTENTION, AEP_BAD_WEATHER, AEP_CARRY_MORE, AEP_CLAIRVOYANCE, AEP_CLAIRVOYANCE_PLUS, AEP_DEX_DOWN, AEP_DEX_UP, AEP_EVIL, AEP_FORCE_TELEPORT, AEP_FUN, AEP_GLOW, AEP_HUNGER, AEP_INT_DOWN, AEP_INT_UP, AEP_INVISIBLE, AEP_MOVEMENT_NOISE, AEP_MUTAGENIC, AEP_PBLUE, AEP_PER_DOWN, AEP_PER_UP, AEP_PSYSHIELD, AEP_RADIOACTIVE, AEP_RESIST_ELECTRICITY, AEP_SCHIZO, AEP_SICK, AEP_SMOKE, AEP_SNAKES, AEP_SPEED_DOWN, AEP_SPEED_UP, AEP_STEALTH, AEP_STR_DOWN, AEP_STR_UP, AEP_SUPER_CLAIRVOYANCE, AEP_THIRST, m_bad, m_good, m_info, m_neutral, m_warning, and string_format().

◆ add_draw_callback()

void game::add_draw_callback ( shared_ptr_fast< draw_callback_t cb)

Definition at line 3370 of file game.cpp.

3371{
3372 draw_callbacks.erase(
3373 std::remove_if( draw_callbacks.begin(), draw_callbacks.end(),
3374 []( const weak_ptr_fast<draw_callback_t> &cbw ) {
3375 return cbw.expired();
3376 } ),
3377 draw_callbacks.end()
3378 );
3379 draw_callbacks.emplace_back( cb );
3380 cb->added = true;
3382}
void invalidate_main_ui_adaptor() const
Definition: game.cpp:3335
std::vector< weak_ptr_fast< draw_callback_t > > draw_callbacks
Definition: game.h:251
std::weak_ptr< T > weak_ptr_fast
Definition: memory_fast.h:17

References draw_callbacks, and invalidate_main_ui_adaptor().

Referenced by get_player_input(), list_items(), list_monsters(), look_around(), pickup(), and zones_manager().

◆ add_npc_follower()

void game::add_npc_follower ( const character_id id)

Add follower id to set of followers.

Definition at line 1956 of file game.cpp.

1957{
1958 follower_ids.insert( id );
1959 u.follower_ids.insert( id );
1960}
std::set< character_id > follower_ids
Definition: game.h:1087
std::set< character_id > follower_ids
Definition: player.h:709

References follower_ids, player::follower_ids, and u.

Referenced by validate_npc_followers().

◆ all_creatures()

game::Creature_range game::all_creatures ( )

Returns an anonymous range that contains all creatures.

The range allows iteration via a range-based for loop, e.g. for( Creature &critter : all_creatures() ) { ... }. One shall not store the returned range nor the iterators. One can freely remove and add creatures to the game during the iteration. Added creatures will not be iterated over.

Definition at line 12501 of file game.cpp.

12502{
12503 return Creature_range( *this );
12504}
friend class Creature_range
Definition: game.h:360

References Creature_range.

Referenced by draw_ter(), get_creature_if(), and get_creatures_if().

◆ all_monsters()

game::monster_range game::all_monsters ( )

Same as all_creatures but iterators only over monsters.

Definition at line 12506 of file game.cpp.

12507{
12508 return monster_range( *this );
12509}
friend class monster_range
Definition: game.h:359

References monster_range.

Referenced by cleanup_at_end(), disp_NPCs(), get_fishable_monsters(), monmove(), place_player_overmap(), shift_monsters(), start_game(), validate_mounted_npcs(), and vertical_move().

◆ all_npcs()

game::npc_range game::all_npcs ( )

Same as all_creatures but iterators only over npcs.

Definition at line 12511 of file game.cpp.

12512{
12513 return npc_range( *this );
12514}

Referenced by do_turn(), and get_npcs_if().

◆ allies()

std::vector< npc * > game::allies ( )

Get all living player allies.

Definition at line 12415 of file game.cpp.

12416{
12417 return get_npcs_if( [&]( const npc & guy ) {
12418 if( !guy.is_hallucination() ) {
12419 return guy.is_ally( g->u );
12420 } else {
12421 return false;
12422 }
12423 } );
12424}
std::vector< npc * > get_npcs_if(const std::function< bool(const npc &)> &pred)
Definition: game.cpp:12438
Definition: npc.h:781
bool is_hallucination() const override
Definition: npc.cpp:3257

References get_npcs_if(), and npc::is_hallucination().

◆ assign_mission_id()

int game::assign_mission_id ( )

Returns the next available mission id.

Definition at line 1944 of file game.cpp.

1945{
1946 int ret = next_mission_id;
1948 return ret;
1949}

References next_mission_id, and cata::hash64_detail::ret.

◆ assign_npc_id()

character_id game::assign_npc_id ( )

Definition at line 3927 of file game.cpp.

3928{
3930 ++next_npc_id;
3931 return ret;
3932}

References next_npc_id, and cata::hash64_detail::ret.

Referenced by load(), and start_game().

◆ autopilot_vehicles()

void game::autopilot_vehicles ( )

process vehicles that are following the player

Definition at line 1750 of file game.cpp.

1751{
1752 for( wrapped_vehicle &veh : m.get_vehicles() ) {
1753 vehicle *&v = veh.v;
1754 if( v->is_following ) {
1755 v->drive_to_local_target( g->m.getabs( u.pos() ), true );
1756 } else if( v->is_patrolling ) {
1757 v->autopilot_patrol();
1758 }
1759 }
1760}
const tripoint & pos() const override
Definition: character.cpp:702
VehicleList get_vehicles()
Definition: map.cpp:232
A vehicle as a whole with all its components.
Definition: vehicle.h:675
void autopilot_patrol()
Definition: vehicle.cpp:701
bool is_following
Definition: vehicle.h:1924
bool is_patrolling
Definition: vehicle.h:1925
void drive_to_local_target(const tripoint &target, bool follow_protocol)
Definition: vehicle.cpp:816

References vehicle::autopilot_patrol(), vehicle::drive_to_local_target(), g, map::get_vehicles(), vehicle::is_following, vehicle::is_patrolling, m, Character::pos(), and u.

Referenced by do_turn().

◆ autosave()

void game::autosave ( )
private

Definition at line 11835 of file game.cpp.

11836{
11837 //Don't autosave if the min-autosave interval has not passed since the last autosave/quicksave.
11838 if( time( nullptr ) < last_save_timestamp + 60 * get_option<int>( "AUTOSAVE_MINUTES" ) ) {
11839 return;
11840 }
11841 quicksave(); //Driving checks are handled by quicksave()
11842}
time_t last_save_timestamp
Definition: game.h:1089
void quicksave()
Definition: game.cpp:11790

References last_save_timestamp, and quicksave().

Referenced by do_turn().

◆ butcher()

void game::butcher ( )
private

Definition at line 8554 of file game.cpp.

8555{
8556 static const std::string salvage_string = "salvage";
8557 if( u.controlling_vehicle ) {
8558 add_msg( m_info, _( "You can't butcher while driving!" ) );
8559 return;
8560 }
8561
8562 const int factor = u.max_quality( quality_id( "BUTCHER" ) );
8563 const int factorD = u.max_quality( quality_id( "CUT_FINE" ) );
8564 const std::string no_knife_msg = _( "You don't have a butchering tool." );
8565 const std::string no_corpse_msg = _( "There are no corpses here to butcher." );
8566
8567 //You can't butcher on sealed terrain- you have to smash/shovel/etc it open first
8568 if( m.has_flag( "SEALED", u.pos() ) ) {
8569 if( m.sees_some_items( u.pos(), u ) ) {
8570 add_msg( m_info, _( "You can't access the items here." ) );
8571 } else if( factor > INT_MIN || factorD > INT_MIN ) {
8572 add_msg( m_info, no_corpse_msg );
8573 } else {
8574 add_msg( m_info, no_knife_msg );
8575 }
8576 return;
8577 }
8578
8579 const item *first_item_without_tools = nullptr;
8580 // Indices of relevant items
8581 std::vector<map_stack::iterator> corpses;
8582 std::vector<map_stack::iterator> disassembles;
8583 std::vector<map_stack::iterator> salvageables;
8584 map_stack items = m.i_at( u.pos() );
8585 const inventory &crafting_inv = u.crafting_inventory();
8586
8587 // TODO: Properly handle different material whitelists
8588 // TODO: Improve quality of this section
8589 auto salvage_filter = []( item it ) {
8590 const auto usable = it.get_usable_item( salvage_string );
8591 return usable != nullptr;
8592 };
8593
8594 std::vector< item * > salvage_tools = u.items_with( salvage_filter );
8595 int salvage_tool_index = INT_MIN;
8596 item *salvage_tool = nullptr;
8597 const salvage_actor *salvage_iuse = nullptr;
8598 if( !salvage_tools.empty() ) {
8599 salvage_tool = salvage_tools.front();
8600 salvage_tool_index = u.get_item_position( salvage_tool );
8601 item *usable = salvage_tool->get_usable_item( salvage_string );
8602 salvage_iuse = dynamic_cast<const salvage_actor *>(
8603 usable->get_use( salvage_string )->get_actor_ptr() );
8604 }
8605
8606 // Reserve capacity for each to hold entire item set if necessary to prevent
8607 // reallocations later on
8608 corpses.reserve( items.size() );
8609 salvageables.reserve( items.size() );
8610 disassembles.reserve( items.size() );
8611
8612 // Split into corpses, disassemble-able, and salvageable items
8613 // It's not much additional work to just generate a corpse list and
8614 // clear it later, but does make the splitting process nicer.
8615 for( map_stack::iterator it = items.begin(); it != items.end(); ++it ) {
8616 if( it->is_corpse() ) {
8617 corpses.push_back( it );
8618 } else {
8619 if( ( salvage_tool_index != INT_MIN ) && salvage_iuse->valid_to_cut_up( *it ) ) {
8620 salvageables.push_back( it );
8621 }
8622 if( u.can_disassemble( *it, crafting_inv ).success() ) {
8623 disassembles.push_back( it );
8624 } else if( !first_item_without_tools ) {
8625 first_item_without_tools = &*it;
8626 }
8627 }
8628 }
8629
8630 // Clear corpses if butcher and dissect factors are INT_MIN
8631 if( factor == INT_MIN && factorD == INT_MIN ) {
8632 corpses.clear();
8633 }
8634
8635 if( corpses.empty() && disassembles.empty() && salvageables.empty() ) {
8636 if( factor > INT_MIN || factorD > INT_MIN ) {
8637 add_msg( m_info, no_corpse_msg );
8638 } else {
8639 add_msg( m_info, no_knife_msg );
8640 }
8641
8642 if( first_item_without_tools ) {
8643 add_msg( m_info, _( "You don't have the necessary tools to disassemble any items here." ) );
8644 // Just for the "You need x to disassemble y" messages
8645 const auto ret = u.can_disassemble( *first_item_without_tools, crafting_inv );
8646 if( !ret.success() ) {
8647 add_msg( m_info, "%s", ret.c_str() );
8648 }
8649 }
8650 return;
8651 }
8652
8653 Creature *hostile_critter = is_hostile_very_close();
8654 if( hostile_critter != nullptr ) {
8655 if( !query_yn( _( "You see %s nearby! Start butchering anyway?" ),
8656 hostile_critter->disp_name() ) ) {
8657 return;
8658 }
8659 }
8660
8661 // Magic indices for special butcher options
8662 enum : int {
8663 MULTISALVAGE = MAX_ITEM_IN_SQUARE + 1,
8664 MULTIBUTCHER,
8665 MULTIDISASSEMBLE_ONE,
8666 MULTIDISASSEMBLE_ALL,
8667 NUM_BUTCHER_ACTIONS
8668 };
8669 // What are we butchering (i.e.. which vector to pick indices from)
8670 enum {
8671 BUTCHER_CORPSE,
8672 BUTCHER_DISASSEMBLE,
8673 BUTCHER_SALVAGE,
8674 BUTCHER_OTHER // For multisalvage etc.
8675 } butcher_select = BUTCHER_CORPSE;
8676 // Index to std::vector of iterators...
8677 int indexer_index = 0;
8678
8679 // Generate the indexed stacks so we can display them nicely
8680 const auto disassembly_stacks = generate_butcher_stack_display( disassembles );
8681 const auto salvage_stacks = generate_butcher_stack_display( salvageables );
8682 // Always ask before cutting up/disassembly, but not before butchery
8683 size_t ret = 0;
8684 if( !corpses.empty() || !disassembles.empty() || !salvageables.empty() ) {
8685 uilist kmenu;
8686 kmenu.text = _( "Choose corpse to butcher / item to disassemble" );
8687
8688 size_t i = 0;
8689 // Add corpses, disassembleables, and salvagables to the UI
8690 add_corpses( kmenu, corpses, i );
8691 add_disassemblables( kmenu, disassembly_stacks, i );
8692 if( salvage_iuse && !salvageables.empty() ) {
8693 add_salvagables( kmenu, salvage_stacks, i, *salvage_iuse );
8694 }
8695
8696 if( corpses.size() > 1 ) {
8697 kmenu.addentry( MULTIBUTCHER, true, 'b', _( "Butcher everything" ) );
8698 }
8699 if( disassembles.size() > 1 ) {
8700 int time_to_disassemble = 0;
8701 int time_to_disassemble_all = 0;
8702 for( const auto &stack : disassembly_stacks ) {
8703 const int time = recipe_dictionary::get_uncraft( stack.first->typeId() ).time;
8704 time_to_disassemble += time;
8705 time_to_disassemble_all += time * stack.second;
8706 }
8707
8708 kmenu.addentry_col( MULTIDISASSEMBLE_ONE, true, 'D', _( "Disassemble everything once" ),
8709 to_string_clipped( time_duration::from_turns( time_to_disassemble / 100 ) ) );
8710 kmenu.addentry_col( MULTIDISASSEMBLE_ALL, true, 'd', _( "Disassemble everything recursively" ),
8711 to_string_clipped( time_duration::from_turns( time_to_disassemble_all / 100 ) ) );
8712 }
8713 if( salvage_iuse && salvageables.size() > 1 ) {
8714 int time_to_salvage = 0;
8715 for( const auto &stack : salvage_stacks ) {
8716 time_to_salvage += salvage_iuse->time_to_cut_up( *stack.first ) * stack.second;
8717 }
8718
8719 kmenu.addentry_col( MULTISALVAGE, true, 'z', _( "Cut up everything" ),
8720 to_string_clipped( time_duration::from_turns( time_to_salvage / 100 ) ) );
8721 }
8722
8723 kmenu.query();
8724
8725 if( kmenu.ret < 0 || kmenu.ret >= NUM_BUTCHER_ACTIONS ) {
8726 return;
8727 }
8728
8729 ret = static_cast<size_t>( kmenu.ret );
8730 if( ret >= MULTISALVAGE && ret < NUM_BUTCHER_ACTIONS ) {
8731 butcher_select = BUTCHER_OTHER;
8732 indexer_index = ret;
8733 } else if( ret < corpses.size() ) {
8734 butcher_select = BUTCHER_CORPSE;
8735 indexer_index = ret;
8736 } else if( ret < corpses.size() + disassembly_stacks.size() ) {
8737 butcher_select = BUTCHER_DISASSEMBLE;
8738 indexer_index = ret - corpses.size();
8739 } else if( ret < corpses.size() + disassembly_stacks.size() + salvage_stacks.size() ) {
8740 butcher_select = BUTCHER_SALVAGE;
8741 indexer_index = ret - corpses.size() - disassembly_stacks.size();
8742 } else {
8743 debugmsg( "Invalid butchery index: %d", ret );
8744 return;
8745 }
8746 }
8747
8748 if( !u.has_morale_to_craft() ) {
8749 if( butcher_select == BUTCHER_CORPSE || indexer_index == MULTIBUTCHER ) {
8750 add_msg( m_info,
8751 _( "You are not in the mood and the prospect of guts and blood on your hands convinces you to turn away." ) );
8752 } else {
8753 add_msg( m_info,
8754 _( "You are not in the mood and the prospect of work stops you before you begin." ) );
8755 }
8756 return;
8757 }
8758 const auto helpers = u.get_crafting_helpers( 3 );
8759 for( const npc *np : helpers ) {
8760 add_msg( m_info, _( "%s helps with this task…" ), np->name );
8761 }
8762 switch( butcher_select ) {
8763 case BUTCHER_OTHER:
8764 switch( indexer_index ) {
8765 case MULTISALVAGE:
8766 u.assign_activity( activity_id( "ACT_LONGSALVAGE" ), 0, salvage_tool_index );
8767 break;
8768 case MULTIBUTCHER:
8769 butcher_submenu( corpses );
8770 for( map_stack::iterator &it : corpses ) {
8771 u.activity.targets.emplace_back( map_cursor( u.pos() ), &*it );
8772 }
8773 break;
8774 case MULTIDISASSEMBLE_ONE:
8775 u.disassemble_all( true );
8776 break;
8777 case MULTIDISASSEMBLE_ALL:
8778 u.disassemble_all( false );
8779 break;
8780 default:
8781 debugmsg( "Invalid butchery type: %d", indexer_index );
8782 return;
8783 }
8784 break;
8785 case BUTCHER_CORPSE: {
8786 butcher_submenu( corpses, indexer_index );
8787 u.activity.targets.emplace_back( map_cursor( u.pos() ), &*corpses[indexer_index] );
8788 }
8789 break;
8790 case BUTCHER_DISASSEMBLE: {
8791 // Pick index of first item in the disassembly stack
8792 item *const target = &*disassembly_stacks[indexer_index].first;
8793 u.disassemble( item_location( map_cursor( u.pos() ), target ), true );
8794 }
8795 break;
8796 case BUTCHER_SALVAGE: {
8797 if( !salvage_iuse || !salvage_tool ) {
8798 debugmsg( "null salve_iuse or salvage_tool" );
8799 } else {
8800 // Pick index of first item in the salvage stack
8801 item *const target = &*salvage_stacks[indexer_index].first;
8802 item_location item_loc( map_cursor( u.pos() ), target );
8803 salvage_iuse->cut_up( u, *salvage_tool, item_loc );
8804 }
8805 }
8806 break;
8807 }
8808}
string_id< activity_type > activity_id
Definition: activity_type.h:15
static std::string to_string_clipped(const int num, const clipped_unit type, const clipped_align align)
Definition: calendar.cpp:228
bool controlling_vehicle
Definition: character.h:285
player_activity activity
Definition: character.h:1574
int get_item_position(const item *it) const
Returns the item position (suitable for i_at or similar) of a specific item.
Definition: character.cpp:2391
bool has_morale_to_craft() const
Definition: crafting.cpp:329
const inventory & crafting_inventory(bool clear_path)
Definition: crafting.cpp:545
void assign_activity(const activity_id &type, int moves=calendar::INDEFINITELY_LONG, int index=-1, int pos=INT_MIN, const std::string &name="")
Legacy activity assignment, does not work for any activites using the new activity_actor class and ma...
Definition: character.cpp:9021
virtual std::string disp_name(bool possessive=false, bool capitalize_first=false) const =0
Creature * is_hostile_very_close()
Definition: game.cpp:3941
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
size_t size() const
Definition: item_stack.cpp:10
iterator begin()
Definition: item_stack.cpp:28
iterator end()
Definition: item_stack.cpp:33
Definition: item.h:176
item * get_usable_item(const std::string &use_name)
Checks this item and its contents (recursively) for types that have use_function with type use_name.
Definition: item.cpp:7731
const use_function * get_use(const std::string &use_name) const
Returns the pointer to use_function with name use_name assigned to the type of this item or any of it...
Definition: item.cpp:7705
Definition: map.h:101
bool has_flag(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2304
map_stack i_at(const tripoint &p)
Definition: map.cpp:4077
bool sees_some_items(const tripoint &p, const Creature &who) const
Check if creature can see some items at p.
Definition: map.cpp:4748
std::vector< item_location > targets
void disassemble_all(bool one_pass)
Definition: crafting.cpp:2030
std::vector< npc * > get_crafting_helpers(size_t max=0) const
Returns nearby NPCs ready and willing to help with crafting or some other manual task.
Definition: crafting.cpp:2322
ret_val< bool > can_disassemble(const item &obj, const inventory &inv) const
Check if the player can disassemble an item using the current crafting inventory.
Definition: crafting.cpp:1855
bool disassemble()
Definition: crafting.cpp:1928
static const recipe & get_uncraft(const itype_id &id)
Returns disassembly recipe (or null recipe if no match)
int time
Definition: recipe.h:59
Cuts stuff up into components.
Definition: iuse_actor.h:528
bool valid_to_cut_up(const item &it) const
int cut_up(player &p, item &it, item_location &cut) const
int time_to_cut_up(const item &it) const
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
uilist: scrolling vertical list menu
Definition: ui.h:187
int ret
Definition: ui.h:412
void addentry_col(int r, bool e, int k, const std::string &str, const std::string &column, const std::string &desc="")
Definition: ui.cpp:952
std::string text
Definition: ui.h:320
void addentry(const std::string &str)
Definition: ui.cpp:932
int max_quality(const quality_id &qual) const
Return maximum tool quality level provided by instance or INT_MIN if not found.
Definition: visitable.cpp:274
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:322
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:74
static void butcher_submenu(const std::vector< map_stack::iterator > &corpses, int corpse=-1)
Definition: game.cpp:8405
static void add_salvagables(uilist &menu, const std::vector< std::pair< map_stack::iterator, int > > &stacks, size_t &menu_index, const salvage_actor &salvage_iuse)
Definition: game.cpp:8363
static void add_disassemblables(uilist &menu, const std::vector< std::pair< map_stack::iterator, int > > &stacks, size_t &menu_index)
Definition: game.cpp:8384
static std::vector< std::pair< map_stack::iterator, int > > generate_butcher_stack_display(const std::vector< map_stack::iterator > &its)
Definition: game.cpp:8316
static void add_corpses(uilist &menu, const std::vector< map_stack::iterator > &its, size_t &menu_index)
Definition: game.cpp:8351
static constexpr int MAX_ITEM_IN_SQUARE
void query(bool loop=true, int timeout=-1)
Handle input and update display.
Definition: ui.cpp:828
bool query_yn(const std::string &text)
Definition: output.cpp:698
iuse_actor * get_actor_ptr()
Definition: iuse.h:315
string_id< quality > quality_id
Definition: type_id.h:158

References _, Character::activity, add_corpses(), add_disassemblables(), add_msg(), add_salvagables(), uilist::addentry(), uilist::addentry_col(), Character::assign_activity(), item_stack::begin(), butcher_submenu(), player::can_disassemble(), Character::controlling_vehicle, Character::crafting_inventory(), salvage_actor::cut_up(), debugmsg, player::disassemble(), player::disassemble_all(), Creature::disp_name(), item_stack::end(), time_duration::from_turns(), generate_butcher_stack_display(), use_function::get_actor_ptr(), player::get_crafting_helpers(), Character::get_item_position(), recipe_dictionary::get_uncraft(), item::get_usable_item(), item::get_use(), map::has_flag(), Character::has_morale_to_craft(), map::i_at(), is_hostile_very_close(), visitable< T >::items_with(), m, m_info, MAX_ITEM_IN_SQUARE, visitable< T >::max_quality(), Character::pos(), uilist::query(), query_yn(), cata::hash64_detail::ret, uilist::ret, map::sees_some_items(), item_stack::size(), player_activity::targets, uilist::text, recipe::time, salvage_actor::time_to_cut_up(), to_string_clipped(), u, and salvage_actor::valid_to_cut_up().

Referenced by handle_action().

◆ calc_driving_offset()

void game::calc_driving_offset ( vehicle veh = nullptr)

Definition at line 1331 of file game.cpp.

1332{
1333 if( veh == nullptr || !get_option<bool>( "DRIVING_VIEW_OFFSET" ) ) {
1335 return;
1336 }
1337 const int g_light_level = static_cast<int>( light_level( u.posz() ) );
1338 const int light_sight_range = u.sight_range( g_light_level );
1339 int sight = std::max( veh_lumi( *veh ), light_sight_range );
1340
1341 // The maximal offset will leave at least this many tiles
1342 // between the PC and the edge of the main window.
1343 static const int border_range = 2;
1344 point max_offset( ( getmaxx( w_terrain ) + 1 ) / 2 - border_range - 1,
1345 ( getmaxy( w_terrain ) + 1 ) / 2 - border_range - 1 );
1346
1347 // velocity at or below this results in no offset at all
1348 static const float min_offset_vel = 1 * vehicles::vmiph_per_tile;
1349 // velocity at or above this results in maximal offset
1350 static const float max_offset_vel = std::min( max_offset.y, max_offset.x ) *
1352 float velocity = veh->velocity;
1353 rl_vec2d offset = veh->move_vec();
1354 if( !veh->skidding && veh->player_in_control( u ) &&
1355 std::abs( veh->cruise_velocity - veh->velocity ) < 7 * vehicles::vmiph_per_tile ) {
1356 // Use the cruise controlled velocity, but only if
1357 // it is not too different from the actual velocity.
1358 // The actual velocity changes too often (see above slowdown).
1359 // Using it makes would make the offset change far too often.
1360 offset = veh->face_vec();
1361 velocity = veh->cruise_velocity;
1362 }
1363 float rel_offset;
1364 if( std::fabs( velocity ) < min_offset_vel ) {
1365 rel_offset = 0;
1366 } else if( std::fabs( velocity ) > max_offset_vel ) {
1367 rel_offset = ( velocity > 0 ) ? 1 : -1;
1368 } else {
1369 rel_offset = ( velocity - min_offset_vel ) / ( max_offset_vel - min_offset_vel );
1370 }
1371 // Squeeze into the corners, by making the offset vector longer,
1372 // the PC is still in view as long as both offset.x and
1373 // offset.y are <= 1
1374 if( std::fabs( offset.x ) > std::fabs( offset.y ) && std::fabs( offset.x ) > 0.2 ) {
1375 offset.y /= std::fabs( offset.x );
1376 offset.x = ( offset.x > 0 ) ? +1 : -1;
1377 } else if( std::fabs( offset.y ) > 0.2 ) {
1378 offset.x /= std::fabs( offset.y );
1379 offset.y = offset.y > 0 ? +1 : -1;
1380 }
1381 offset.x *= rel_offset;
1382 offset.y *= rel_offset;
1383 offset.x *= max_offset.x;
1384 offset.y *= max_offset.y;
1385 // [ ----@---- ] sight=6
1386 // [ --@------ ] offset=2
1387 // [ -@------# ] offset=3
1388 // can see sights square in every direction, total visible area is
1389 // (2*sight+1)x(2*sight+1), but the window is only
1390 // getmaxx(w_terrain) x getmaxy(w_terrain)
1391 // The area outside of the window is maxoff (sight-getmax/2).
1392 // If that value is <= 0, the whole visible area fits the window.
1393 // don't apply the view offset at all.
1394 // If the offset is > maxoff, only apply at most maxoff, everything
1395 // above leads to invisible area in front of the car.
1396 // It will display (getmax/2+offset) squares in one direction and
1397 // (getmax/2-offset) in the opposite direction (centered on the PC).
1398 const point maxoff( ( sight * 2 + 1 - getmaxx( w_terrain ) ) / 2,
1399 ( sight * 2 + 1 - getmaxy( w_terrain ) ) / 2 );
1400 if( maxoff.x <= 0 ) {
1401 offset.x = 0;
1402 } else if( offset.x > 0 && offset.x > maxoff.x ) {
1403 offset.x = maxoff.x;
1404 } else if( offset.x < 0 && -offset.x > maxoff.x ) {
1405 offset.x = -maxoff.x;
1406 }
1407 if( maxoff.y <= 0 ) {
1408 offset.y = 0;
1409 } else if( offset.y > 0 && offset.y > maxoff.y ) {
1410 offset.y = maxoff.y;
1411 } else if( offset.y < 0 && -offset.y > maxoff.y ) {
1412 offset.y = -maxoff.y;
1413 }
1414
1415 // Turn the offset into a vector that increments the offset toward the desired position
1416 // instead of setting it there instantly, should smooth out jerkiness.
1417 const point offset_difference( -driving_view_offset + point( offset.x, offset.y ) );
1418
1419 const point offset_sign( ( offset_difference.x < 0 ) ? -1 : 1,
1420 ( offset_difference.y < 0 ) ? -1 : 1 );
1421 // Shift the current offset in the direction of the calculated offset by one tile
1422 // per draw event, but snap to calculated offset if we're close enough to avoid jitter.
1423 offset.x = ( std::abs( offset_difference.x ) > 1 ) ?
1424 ( driving_view_offset.x + offset_sign.x ) : offset.x;
1425 offset.y = ( std::abs( offset_difference.y ) > 1 ) ?
1426 ( driving_view_offset.y + offset_sign.y ) : offset.y;
1427
1428 set_driving_view_offset( point( offset.x, offset.y ) );
1429}
int posz() const override
Definition: character.h:844
int sight_range(int light_level) const override
Returns the player's sight range.
Definition: character.cpp:707
point driving_view_offset
Definition: game.h:1045
catacurses::window w_terrain
Definition: game.h:1035
void set_driving_view_offset(const point &p)
Definition: game.cpp:1688
unsigned char light_level(int zlev) const
Returns coarse number-of-squares of visibility at the current light level.
Definition: game.cpp:3913
rl_vec2d move_vec() const
rl_vec2d face_vec() const
bool skidding
Definition: vehicle.h:1940
bool player_in_control(const Character &p) const
Definition: vehicle.cpp:277
int velocity
Definition: vehicle.h:1861
int cruise_velocity
Definition: vehicle.h:1863
static int veh_lumi(vehicle &veh)
Definition: game.cpp:1313
int getmaxx(const window &win)
Definition: ncurses_def.cpp:58
int getmaxy(const window &win)
Definition: ncurses_def.cpp:63
quantity< V, U > fabs(quantity< V, U > q)
Definition: units_def.h:136
constexpr float vmiph_per_tile
Definition: vehicle.h:68
static constexpr point point_zero
Definition: point.h:274
Definition: point.h:35
int y
Definition: point.h:39
int x
Definition: point.h:38
float y
Definition: point_float.h:13
float x
Definition: point_float.h:12

References vehicle::cruise_velocity, driving_view_offset, units::fabs(), vehicle::face_vec(), catacurses::getmaxx(), catacurses::getmaxy(), light_level(), vehicle::move_vec(), vehicle::player_in_control(), point_zero, Character::posz(), set_driving_view_offset(), Character::sight_range(), vehicle::skidding, u, veh_lumi(), vehicle::velocity, vehicles::vmiph_per_tile, w_terrain, point::x, rl_vec2d::x, point::y, and rl_vec2d::y.

Referenced by do_turn().

◆ cancel_activity_or_ignore_query()

bool game::cancel_activity_or_ignore_query ( distraction_type  type,
const std::string &  text 
)

Asks if the player wants to cancel their activity and if so cancels it.

Additionally checks if the player wants to ignore further distractions.

Definition at line 1789 of file game.cpp.

1790{
1792 if( u.has_distant_destination() ) {
1793 if( cancel_auto_move( u, text ) ) {
1794 return true;
1795 } else {
1797 return false;
1798 }
1799 }
1801 return false;
1802 }
1803 const bool force_uc = get_option<bool>( "FORCE_CAPITAL_YN" );
1804 const auto &allow_key = force_uc ? input_context::disallow_lower_case
1806
1807 const auto &action = query_popup()
1808 .context( "CANCEL_ACTIVITY_OR_IGNORE_QUERY" )
1809 .message( force_uc ?
1810 pgettext( "cancel_activity_or_ignore_query",
1811 "<color_light_red>%s %s (Case Sensitive)</color>" ) :
1812 pgettext( "cancel_activity_or_ignore_query",
1813 "<color_light_red>%s %s</color>" ),
1814 text, u.activity.get_stop_phrase() )
1815 .option( "YES", allow_key )
1816 .option( "NO", allow_key )
1817 .option( "IGNORE", allow_key )
1818 .query()
1819 .action;
1820
1821 if( action == "YES" ) {
1823 return true;
1824 }
1825 if( action == "IGNORE" ) {
1827 for( auto &activity : u.backlog ) {
1828 activity.ignore_distraction( type );
1829 }
1830 }
1831
1834
1835 return false;
1836}
void set_destination(const std::vector< tripoint > &route, const player_activity &new_destination_activity=player_activity())
void cancel_activity()
Definition: character.cpp:9064
std::vector< tripoint > & get_auto_move_route()
std::list< player_activity > backlog
Definition: character.h:1575
bool has_distant_destination() const
static const input_event_filter allow_all_keys
Definition: input.h:541
static const input_event_filter disallow_lower_case
Definition: input.h:540
bool is_distraction_ignored(distraction_type type) const
std::string get_stop_phrase() const
void ignore_distraction(distraction_type type)
UI class for displaying messages or querying player input with popups.
Definition: popup.h:39
query_popup & context(const std::string &cat)
Specify the input context.
Definition: popup.cpp:21
query_popup & option(const std::string &opt)
Specify an action as an option.
Definition: popup.cpp:28
result query()
Query until a valid action or an error happens and return the result.
Definition: popup.cpp:348
query_popup & message(const std::string &fmt, Args &&... args)
Specify the query message.
Definition: popup.h:91
@ action
Definition: dialogue.h:36
@ type
Definition: enums.h:75
static bool cancel_auto_move(player &p, const std::string &text)
Definition: game.cpp:1776
void redraw()
Definition: ui_manager.cpp:285
void refresh_display()
Make changes made to the display visible to the user immediately.
std::string action
Definition: popup.h:68
const char * pgettext(const char *context, const char *msgid)

References action, query_popup::result::action, Character::activity, input_context::allow_all_keys, Character::backlog, Character::cancel_activity(), cancel_auto_move(), query_popup::context(), input_context::disallow_lower_case, Character::get_auto_move_route(), player_activity::get_stop_phrase(), Character::has_distant_destination(), player_activity::ignore_distraction(), invalidate_main_ui_adaptor(), player_activity::is_distraction_ignored(), query_popup::message(), query_popup::option(), pgettext(), query_popup::query(), ui_manager::redraw(), refresh_display(), Character::set_destination(), type, and u.

Referenced by mon_info_update(), monmove(), and process_voluntary_act_interrupt().

◆ cancel_activity_query()

bool game::cancel_activity_query ( const std::string &  text)

Asks if the player wants to cancel their activity, and if so cancels it.

Definition at line 1838 of file game.cpp.

1839{
1841 if( u.has_distant_destination() ) {
1842 if( cancel_auto_move( u, text ) ) {
1843 return true;
1844 } else {
1846 return false;
1847 }
1848 }
1849 if( !u.activity ) {
1850 return false;
1851 }
1852 if( query_yn( "%s %s", text, u.activity.get_stop_phrase() ) ) {
1856 return true;
1857 }
1858 return false;
1859}
void clear_destination()
void resume_backlog_activity()
Definition: character.cpp:9096

References Character::activity, Character::cancel_activity(), cancel_auto_move(), Character::clear_destination(), Character::get_auto_move_route(), player_activity::get_stop_phrase(), Character::has_distant_destination(), invalidate_main_ui_adaptor(), query_yn(), Character::resume_backlog_activity(), Character::set_destination(), and u.

Referenced by handle_key_blocking_activity().

◆ catch_a_monster()

void game::catch_a_monster ( monster fish,
const tripoint pos,
player p,
const time_duration catch_duration 
)

Picks and spawns a random fish from the remaining fish list when a fish is caught.

Definition at line 1762 of file game.cpp.

1764{
1765 //spawn the corpse, rotten by a part of the duration
1767 catch_duration ) ) );
1768 if( u.sees( pos ) ) {
1769 u.add_msg_if_player( m_good, _( "You caught a %s." ), fish->type->nname() );
1770 }
1771 //quietly kill the caught
1772 fish->no_corpse_quiet = true;
1773 fish->die( p );
1774}
bool sees(const tripoint &t, bool is_player=false, int range_mod=0) const override
static item make_corpse(const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
Make a corpse of the given monster type.
Definition: item.cpp:499
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4222
bool no_corpse_quiet
Definition: monster.h:482
void die(Creature *killer) override
Empty function.
Definition: monster.cpp:2243
const mtype * type
Definition: monster.h:478
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:4411
time_point turn
Definition: calendar.cpp:36
mtype_id id
Definition: mtype.h:240
std::string nname(unsigned int quantity=1) const
Definition: mtype.cpp:65

References _, map::add_item_or_charges(), player::add_msg_if_player(), monster::die(), mtype::id, m, m_good, item::make_corpse(), mtype::nname(), monster::no_corpse_quiet, rng(), Character::sees(), calendar::turn, monster::type, and u.

◆ chat()

void game::chat ( )
private

Definition at line 393 of file npctalk.cpp.

394{
395 int volume = g->u.get_shout_volume();
396
397 const std::vector<npc *> available = get_npcs_if( [&]( const npc & guy ) {
398 // TODO: Get rid of the z-level check when z-level vision gets "better"
399 return u.posz() == guy.posz() && u.sees( guy.pos() ) &&
400 rl_dist( u.pos(), guy.pos() ) <= SEEX * 2;
401 } );
402 const int available_count = available.size();
403 const std::vector<npc *> followers = get_npcs_if( [&]( const npc & guy ) {
404 return guy.is_player_ally() && guy.is_following() && guy.can_hear( u.pos(), volume );
405 } );
406 const int follower_count = followers.size();
407 const std::vector<npc *> guards = get_npcs_if( [&]( const npc & guy ) {
408 return guy.mission == NPC_MISSION_GUARD_ALLY &&
409 guy.companion_mission_role_id != "FACTION_CAMP" &&
410 guy.can_hear( u.pos(), volume );
411 } );
412 const int guard_count = guards.size();
413
414 if( g->u.has_trait( trait_PROF_FOODP ) && !( g->u.is_wearing( itype_id( "foodperson_mask" ) ) ||
415 g->u.is_wearing( itype_id( "foodperson_mask_on" ) ) ) ) {
416 g->u.add_msg_if_player( m_warning, _( "You can't speak without your face!" ) );
417 return;
418 }
419 std::vector<vehicle *> animal_vehicles;
420 std::vector<vehicle *> following_vehicles;
421 std::vector<vehicle *> magic_vehicles;
422 std::vector<vehicle *> magic_following_vehicles;
423 for( auto &veh : g->m.get_vehicles() ) {
424 auto &v = veh.v;
425 if( v->has_engine_type( fuel_type_animal, false ) && v->is_owned_by( g->u ) ) {
426 animal_vehicles.push_back( v );
427 if( v->is_following ) {
428 following_vehicles.push_back( v );
429 }
430 }
431 if( v->magic ) {
432 for( const vpart_reference &vp : v->get_all_parts() ) {
433 const vpart_info &vpi = vp.info();
434 if( vpi.has_flag( "MAGIC_FOLLOW" ) ) {
435 magic_vehicles.push_back( v );
436 if( v->is_following ) {
437 magic_following_vehicles.push_back( v );
438 }
439 break;
440 }
441 }
442 }
443 }
444
445 uilist nmenu;
446 nmenu.text = std::string( _( "What do you want to do?" ) );
447
448 if( !available.empty() ) {
449 nmenu.addentry( NPC_CHAT_TALK, true, 't', available_count == 1 ?
450 string_format( _( "Talk to %s" ), available.front()->name ) :
451 _( "Talk to…" )
452 );
453 }
454 nmenu.addentry( NPC_CHAT_YELL, true, 'a', _( "Yell" ) );
455 nmenu.addentry( NPC_CHAT_SENTENCE, true, 'b', _( "Yell a sentence" ) );
456 if( !animal_vehicles.empty() ) {
458 _( "Whistle at your animals pulling vehicles to follow you." ) );
459 }
460 if( !magic_vehicles.empty() ) {
462 _( "Utter a magical command that will order your magical vehicles to follow you." ) );
463 }
464 if( !magic_following_vehicles.empty() ) {
466 _( "Utter a magical command that will order your magical vehicles to stop following you." ) );
467 }
468 if( !following_vehicles.empty() ) {
470 _( "Whistle at your animals pulling vehicles to stop following you." ) );
471 }
472 if( !guards.empty() ) {
473 nmenu.addentry( NPC_CHAT_FOLLOW, true, 'f', guard_count == 1 ?
474 string_format( _( "Tell %s to follow" ), guards.front()->name ) :
475 _( "Tell someone to follow…" )
476 );
477 }
478 if( !followers.empty() ) {
479 nmenu.addentry( NPC_CHAT_GUARD, true, 'g', follower_count == 1 ?
480 string_format( _( "Tell %s to guard" ), followers.front()->name ) :
481 _( "Tell someone to guard…" )
482 );
483 nmenu.addentry( NPC_CHAT_AWAKE, true, 'w', _( "Tell everyone on your team to wake up" ) );
484 nmenu.addentry( NPC_CHAT_MOUNT, true, 'M', _( "Tell everyone on your team to mount up" ) );
485 nmenu.addentry( NPC_CHAT_DISMOUNT, true, 'm', _( "Tell everyone on your team to dismount" ) );
486 nmenu.addentry( NPC_CHAT_DANGER, true, 'D',
487 _( "Tell everyone on your team to prepare for danger" ) );
488 nmenu.addentry( NPC_CHAT_CLEAR_OVERRIDES, true, 'r',
489 _( "Tell everyone on your team to relax (Clear Overrides)" ) );
490 nmenu.addentry( NPC_CHAT_ORDERS, true, 'o', _( "Tell everyone on your team to temporarily…" ) );
491 }
492 std::string message;
493 std::string yell_msg;
494 bool is_order = true;
495 nmenu.query();
496
497 if( nmenu.ret < 0 ) {
498 return;
499 }
500
501 switch( nmenu.ret ) {
502 case NPC_CHAT_TALK: {
503 const int npcselect = npc_select_menu( available, _( "Talk to whom?" ), false );
504 if( npcselect < 0 ) {
505 return;
506 }
507 available[npcselect]->talk_to_u();
508 break;
509 }
510 case NPC_CHAT_YELL:
511 is_order = false;
512 message = _( "loudly." );
513 break;
514 case NPC_CHAT_SENTENCE: {
515 std::string popupdesc = _( "Enter a sentence to yell" );
517 popup.title( _( "Yell a sentence" ) )
518 .width( 64 )
519 .description( popupdesc )
520 .identifier( "sentence" )
521 .max_length( 128 )
522 .query();
523 yell_msg = popup.text();
524 is_order = false;
525 break;
526 }
527 case NPC_CHAT_GUARD: {
528 const int npcselect = npc_select_menu( followers, _( "Who should guard here?" ) );
529 if( npcselect < 0 ) {
530 return;
531 }
532 if( npcselect == follower_count ) {
533 for( npc *them : followers ) {
535 }
536 yell_msg = _( "Everyone guard here!" );
537 } else {
538 talk_function::assign_guard( *followers[npcselect] );
539 yell_msg = string_format( _( "Guard here, %s!" ), followers[npcselect]->name );
540 }
541 break;
542 }
543 case NPC_CHAT_FOLLOW: {
544 const int npcselect = npc_select_menu( guards, _( "Who should follow you?" ) );
545 if( npcselect < 0 ) {
546 return;
547 }
548 if( npcselect == guard_count ) {
549 for( npc *them : guards ) {
551 }
552 yell_msg = _( "Everyone follow me!" );
553 } else {
554 talk_function::stop_guard( *guards[npcselect] );
555 yell_msg = string_format( _( "Follow me, %s!" ), guards[npcselect]->name );
556 }
557 break;
558 }
559 case NPC_CHAT_AWAKE:
560 for( npc *them : followers ) {
561 talk_function::wake_up( *them );
562 }
563 yell_msg = _( "Stay awake!" );
564 break;
565 case NPC_CHAT_MOUNT:
566 for( npc *them : followers ) {
567 if( them->has_effect( effect_riding ) ) {
568 continue;
569 }
571 }
572 yell_msg = _( "Mount up!" );
573 break;
575 for( npc *them : followers ) {
576 if( them->has_effect( effect_riding ) ) {
577 them->npc_dismount();
578 }
579 }
580 yell_msg = _( "Dismount!" );
581 break;
582 case NPC_CHAT_DANGER:
583 for( npc *them : followers ) {
584 them->rules.set_danger_overrides();
585 }
586 yell_msg = _( "We're in danger. Stay awake, stay close, don't go wandering off, "
587 "and don't open any doors." );
588 break;
590 for( npc *p : followers ) {
592 }
593 yell_msg = _( "As you were." );
594 break;
595 case NPC_CHAT_ORDERS:
596 npc_temp_orders_menu( followers );
597 break;
600 break;
603 break;
606 break;
609 break;
610 default:
611 return;
612 }
613
614 if( !yell_msg.empty() ) {
615 message = string_format( "\"%s\"", yell_msg );
616 }
617 if( !message.empty() ) {
618 add_msg( _( "You yell %s" ), message );
619 u.shout( string_format( _( "%s yelling %s" ), u.disp_name(), message ), is_order );
620 }
621
622 u.moves -= 100;
623}
std::string disp_name(bool possessive=false, bool capitalize_first=false) const override
Returns either "you" or the player's name.
Definition: character.cpp:534
void shout(std::string msg="", bool order=false)
Definition: character.cpp:7566
bool can_hear(const tripoint &source, int volume) const
int moves
Definition: creature.h:569
std::string companion_mission_role_id
Definition: npc.h:1318
npc_mission mission
Definition: npc.h:1325
bool is_player_ally() const
Definition: npc.cpp:1984
bool is_following() const
Definition: npc.cpp:2015
Shows a window querying the user for input.
bool has_flag(const std::string &flag) const
Definition: veh_type.h:336
This is a wrapper over a vehicle pointer and a reference to a part of it.
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
static constexpr int SEEX
std::string message
Definition: mapgen.cpp:403
std::string name(type dir)
Get Human readable name of a direction.
Definition: overmap.cpp:4034
void wake_up(npc &)
void find_mount(npc &)
void clear_overrides(npc &p)
void stop_guard(npc &)
void assign_guard(npc &)
quantity< int, volume_in_milliliter_tag > volume
Definition: units_volume.h:16
@ NPC_MISSION_GUARD_ALLY
Definition: npc.h:187
static const efftype_id effect_riding("riding")
static const trait_id trait_PROF_FOODP("PROF_FOODP")
static int npc_select_menu(const std::vector< npc * > &npc_list, const std::string &prompt, const bool everyone=true)
Definition: npctalk.cpp:219
static void tell_magic_veh_stop_following()
Definition: npctalk.cpp:376
static void tell_veh_stop_following()
Definition: npctalk.cpp:339
static void assign_veh_to_follow()
Definition: npctalk.cpp:350
static void npc_temp_orders_menu(const std::vector< npc * > &npc_list)
Definition: npctalk.cpp:251
static const itype_id fuel_type_animal("animal")
@ NPC_CHAT_MOUNT
Definition: npctalk.cpp:199
@ NPC_CHAT_COMMAND_MAGIC_VEHICLE_STOP_FOLLOW
Definition: npctalk.cpp:213
@ NPC_CHAT_YELL
Definition: npctalk.cpp:194
@ NPC_CHAT_FOLLOW
Definition: npctalk.cpp:197
@ NPC_CHAT_GUARD
Definition: npctalk.cpp:196
@ NPC_CHAT_DISMOUNT
Definition: npctalk.cpp:200
@ NPC_CHAT_ANIMAL_VEHICLE_FOLLOW
Definition: npctalk.cpp:210
@ NPC_CHAT_ORDERS
Definition: npctalk.cpp:202
@ NPC_CHAT_SENTENCE
Definition: npctalk.cpp:195
@ NPC_CHAT_CLEAR_OVERRIDES
Definition: npctalk.cpp:209
@ NPC_CHAT_DANGER
Definition: npctalk.cpp:201
@ NPC_CHAT_AWAKE
Definition: npctalk.cpp:198
@ NPC_CHAT_ANIMAL_VEHICLE_STOP_FOLLOW
Definition: npctalk.cpp:211
@ NPC_CHAT_TALK
Definition: npctalk.cpp:193
@ NPC_CHAT_COMMAND_MAGIC_VEHICLE_FOLLOW
Definition: npctalk.cpp:212
static void tell_magic_veh_to_follow()
Definition: npctalk.cpp:360
int popup(const std::string &text, PopupFlags flags)
Definition: output.cpp:764

References _, add_msg(), uilist::addentry(), talk_function::assign_guard(), assign_veh_to_follow(), available, Character::can_hear(), talk_function::clear_overrides(), npc::companion_mission_role_id, Character::disp_name(), effect_riding, talk_function::find_mount(), fuel_type_animal, g, get_npcs_if(), vpart_info::has_flag(), npc::is_following(), npc::is_player_ally(), m_warning, mapgen_defer::message, npc::mission, Creature::moves, om_direction::name(), NPC_CHAT_ANIMAL_VEHICLE_FOLLOW, NPC_CHAT_ANIMAL_VEHICLE_STOP_FOLLOW, NPC_CHAT_AWAKE, NPC_CHAT_CLEAR_OVERRIDES, NPC_CHAT_COMMAND_MAGIC_VEHICLE_FOLLOW, NPC_CHAT_COMMAND_MAGIC_VEHICLE_STOP_FOLLOW, NPC_CHAT_DANGER, NPC_CHAT_DISMOUNT, NPC_CHAT_FOLLOW, NPC_CHAT_GUARD, NPC_CHAT_MOUNT, NPC_CHAT_ORDERS, NPC_CHAT_SENTENCE, NPC_CHAT_TALK, NPC_CHAT_YELL, NPC_MISSION_GUARD_ALLY, npc_select_menu(), npc_temp_orders_menu(), popup(), Character::pos(), Character::posz(), uilist::query(), uilist::ret, rl_dist(), Character::sees(), SEEX, Character::shout(), talk_function::stop_guard(), string_format(), tell_magic_veh_stop_following(), tell_magic_veh_to_follow(), tell_veh_stop_following(), uilist::text, trait_PROF_FOODP, u, and talk_function::wake_up().

Referenced by handle_action().

◆ check_mod_data()

bool game::check_mod_data ( const std::vector< mod_id > &  opts,
loading_ui ui 
)

Check if mods can be successfully loaded.

Parameters
optscheck specific mods (or all if unspecified)
Returns
whether all mods were successfully loaded

Definition at line 342 of file game.cpp.

343{
344 auto &tree = world_generator->get_mod_manager().get_tree();
345
346 // deduplicated list of mods to check
347 std::set<mod_id> check( opts.begin(), opts.end() );
348
349 // if no specific mods specified check all non-obsolete mods
350 if( check.empty() ) {
351 for( const mod_id &e : world_generator->get_mod_manager().all_mods() ) {
352 if( !e->obsolete ) {
353 check.emplace( e );
354 }
355 }
356 }
357
358 if( check.empty() ) {
359 world_generator->set_active_world( nullptr );
360 world_generator->init();
361 const std::vector<mod_id> mods_empty;
362 WORLDPTR test_world = world_generator->make_new_world( mods_empty );
363 world_generator->set_active_world( test_world );
364
365 // if no loadable mods then test core data only
366 try {
369 } catch( const std::exception &err ) {
370 std::cerr << "Error loading data from json: " << err.what() << std::endl;
371 }
372
373 std::string world_name = world_generator->active_world->world_name;
374 world_generator->delete_world( world_name, true );
375
378 }
379
380 for( const auto &e : check ) {
381 world_generator->set_active_world( nullptr );
382 world_generator->init();
383 const std::vector<mod_id> mods_empty;
384 WORLDPTR test_world = world_generator->make_new_world( mods_empty );
385 if( !test_world ) {
386 std::cerr << "Failed to generate test world." << std::endl;
387 return false;
388 }
389 world_generator->set_active_world( test_world );
390
391 if( !e.is_valid() ) {
392 std::cerr << "Unknown mod: " << e.str() << std::endl;
393 return false;
394 }
395
396 const MOD_INFORMATION &mod = *e;
397
398 if( !tree.is_available( mod.ident ) ) {
399 std::cerr << "Missing dependencies: " << mod.name() << "\n"
400 << tree.get_node( mod.ident )->s_errors() << std::endl;
401 return false;
402 }
403
404 std::cout << "Checking mod " << mod.name() << " [" << mod.ident.str() << "]" << std::endl;
405
406 try {
408
409 // Load any dependencies
410 for( auto &dep : tree.get_dependencies_of_X_as_strings( mod.ident ) ) {
411 load_data_from_dir( dep->path, dep->ident.str(), ui );
412 }
413
414 // Load mod itself
415 load_data_from_dir( mod.path, mod.ident.str(), ui );
417 } catch( const std::exception &err ) {
418 std::cerr << "Error loading data: " << err.what() << std::endl;
419 }
420
421 std::string world_name = world_generator->active_world->world_name;
422 world_generator->delete_world( world_name, true );
423
426 }
427 return true;
428}
void finalize_loaded_data(loading_ui &ui)
Called to finalize the loaded data.
Definition: init.cpp:625
static DynamicDataLoader & get_instance()
Returns the single instance of this class.
Definition: init.cpp:110
void load_data_from_dir(const std::string &path, const std::string &src, loading_ui &ui)
Loads dynamic data from the given directory.
Definition: game.cpp:444
void load_core_data(loading_ui &ui)
Loads core dynamic data.
Definition: game.cpp:435
void reset()
Delete all buffered submaps.
Definition: mapbuffer.cpp:49
int check(unformattable)
Definition: fmtlib_core.h:1610
Definition: overmap_ui.h:17
overmapbuffer overmap_buffer

References detail::check(), overmapbuffer::clear(), DynamicDataLoader::finalize_loaded_data(), DynamicDataLoader::get_instance(), load_core_data(), load_data_from_dir(), MAPBUFFER, overmap_buffer, mapbuffer::reset(), and world_generator.

◆ check_near_zone()

bool game::check_near_zone ( const zone_type_id type,
const tripoint where 
) const

Checks whether or not there is a zone of particular type nearby.

Definition at line 6285 of file game.cpp.

6286{
6287 return zone_manager::get_manager().has_near( type, m.getabs( where ) );
6288}
tripoint getabs(const tripoint &p) const
Translates local (to this map) coordinates of a square to global absolute coordinates.
Definition: map.cpp:8042
static zone_manager & get_manager()
Definition: clzones.cpp:125
bool has_near(const zone_type_id &type, const tripoint &where, int range=MAX_DISTANCE, const faction_id &fac=your_fac) const
Definition: clzones.cpp:700

References zone_manager::get_manager(), map::getabs(), zone_manager::has_near(), m, and type.

◆ check_safe_mode_allowed()

bool game::check_safe_mode_allowed ( bool  repeat_safe_mode_warnings = true)

Check whether movement is allowed according to safe mode settings.

Returns
true if the movement is allowed, otherwise false.

Definition at line 9112 of file game.cpp.

9113{
9114 if( !repeat_safe_mode_warnings && safe_mode_warning_logged ) {
9115 // Already warned player since safe_mode_warning_logged is set.
9116 return false;
9117 }
9118
9119 std::string msg_ignore = press_x( ACTION_IGNORE_ENEMY );
9120 if( !msg_ignore.empty() ) {
9121 std::wstring msg_ignore_wide = utf8_to_wstr( msg_ignore );
9122 // Operate on a wide-char basis to prevent corrupted multi-byte string
9123 msg_ignore_wide[0] = towlower( msg_ignore_wide[0] );
9124 msg_ignore = wstr_to_utf8( msg_ignore_wide );
9125 }
9126
9128 // Automatic and mandatory safemode. Make BLOODY sure the player notices!
9129 if( u.get_int_base() < 5 || u.has_trait( trait_id( "PROF_CHURL" ) ) ) {
9131 _( "There's an angry red dot on your body, %s to brush it off." ), msg_ignore );
9132 } else {
9134 _( "You are being laser-targeted, %s to ignore." ), msg_ignore );
9135 }
9137 return false;
9138 }
9139 if( safe_mode != SAFE_MODE_STOP ) {
9140 return true;
9141 }
9142 // Currently driving around, ignore the monster, they have no chance against a proper car anyway (-:
9143 if( u.controlling_vehicle && !get_option<bool>( "SAFEMODEVEH" ) ) {
9144 return true;
9145 }
9146 // Monsters around and we don't want to run
9147 std::string spotted_creature_name;
9148 const monster_visible_info &mon_visible = u.get_mon_visible();
9149 const auto &new_seen_mon = mon_visible.new_seen_mon;
9150
9151 if( new_seen_mon.empty() ) {
9152 // naming consistent with code in game::mon_info
9153 spotted_creature_name = _( "a survivor" );
9155 } else {
9156 spotted_creature_name = new_seen_mon.back()->name();
9157 get_safemode().lastmon_whitelist = spotted_creature_name;
9158 }
9159
9160 std::string whitelist;
9161 if( !get_safemode().empty() ) {
9162 whitelist = string_format( _( " or %s to whitelist the monster" ),
9164 }
9165
9166 const std::string msg_safe_mode = press_x( ACTION_TOGGLE_SAFEMODE );
9168 _( "Spotted %1$s--safe mode is on! (%2$s to turn it off, %3$s to ignore monster%4$s)" ),
9169 spotted_creature_name, msg_safe_mode, msg_ignore, whitelist );
9171 return false;
9172}
std::string press_x(action_id act)
Definition: action.cpp:449
@ ACTION_IGNORE_ENEMY
Ignore the enemy that triggered safemode.
Definition: action.h:219
@ ACTION_WHITELIST_ENEMY
Whitelist the enemy that triggered safemode.
Definition: action.h:221
@ ACTION_TOGGLE_SAFEMODE
Turn safemode on/off, while leaving autosafemode intact.
Definition: action.h:213
std::wstring utf8_to_wstr(const std::string &str)
std::string wstr_to_utf8(const std::wstring &wstr)
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:103
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1173
int get_int_base() const override
Definition: avatar.cpp:1022
monster_visible_info & get_mon_visible()
Definition: avatar.h:210
std::string lastmon_whitelist
Definition: safemode_ui.h:87
std::string npc_type_name()
Definition: safemode_ui.cpp:44
@ gmf_bypass_cooldown
Definition: enums.h:281
static const efftype_id effect_laserlocked("laserlocked")
@ SAFE_MODE_STOP
Definition: game.h:79
safemode & get_safemode()
Definition: safemode_ui.cpp:33
Structure allowing a combination of game_message_type and game_message_flags.
Definition: enums.h:286
std::vector< shared_ptr_fast< monster > > new_seen_mon
Definition: avatar.h:40

References _, ACTION_IGNORE_ENEMY, ACTION_TOGGLE_SAFEMODE, ACTION_WHITELIST_ENEMY, add_msg(), Character::controlling_vehicle, effect_laserlocked, avatar::get_int_base(), avatar::get_mon_visible(), get_safemode(), gmf_bypass_cooldown, Creature::has_effect(), Character::has_trait(), safemode::lastmon_whitelist, m_warning, monster_visible_info::new_seen_mon, safemode::npc_type_name(), press_x(), safe_mode, SAFE_MODE_STOP, safe_mode_warning_logged, string_format(), u, utf8_to_wstr(), and wstr_to_utf8().

Referenced by handle_action().

◆ check_zone()

bool game::check_zone ( const zone_type_id type,
const tripoint where 
) const

Definition at line 6280 of file game.cpp.

6281{
6282 return zone_manager::get_manager().has( type, m.getabs( where ) );
6283}
bool has(const zone_type_id &type, const tripoint &where, const faction_id &fac=your_fac) const
Definition: clzones.cpp:692

References zone_manager::get_manager(), map::getabs(), zone_manager::has(), m, and type.

◆ cleanup_at_end()

bool game::cleanup_at_end ( )

Definition at line 1027 of file game.cpp.

1028{
1029 if( uquit == QUIT_DIED || uquit == QUIT_SUICIDE ) {
1030 // Put (non-hallucinations) into the overmap so they are not lost.
1031 for( monster &critter : all_monsters() ) {
1032 despawn_monster( critter );
1033 }
1034 // Reset NPC factions and disposition
1036 // Save the factions', missions and set the NPC's overmap coordinates
1037 // Npcs are saved in the overmap.
1038 save_factions_missions_npcs(); //missions need to be saved as they are global for all saves.
1039 // save artifacts.
1041
1042 // and the overmap, and the local map.
1043 save_maps(); //Omap also contains the npcs who need to be saved.
1044 }
1045
1046 if( uquit == QUIT_DIED || uquit == QUIT_SUICIDE ) {
1047 std::vector<std::string> vRip;
1048
1049 int iMaxWidth = 0;
1050 int iNameLine = 0;
1051 int iInfoLine = 0;
1052
1055 if( !( u.has_trait( trait_id( "CANNIBAL" ) ) || u.has_trait( trait_id( "PSYCHOPATH" ) ) ) ) {
1056 vRip.emplace_back( " _______ ___" );
1057 vRip.emplace_back( " < `/ |" );
1058 vRip.emplace_back( " > _ _ (" );
1059 vRip.emplace_back( " | |_) | |_) |" );
1060 vRip.emplace_back( " | | \\ | | |" );
1061 vRip.emplace_back( " ______.__%_| |_________ __" );
1062 vRip.emplace_back( " _/ \\| |" );
1063 iNameLine = vRip.size();
1064 vRip.emplace_back( "| <" );
1065 vRip.emplace_back( "| |" );
1066 iMaxWidth = utf8_width( vRip.back() );
1067 vRip.emplace_back( "| |" );
1068 vRip.emplace_back( "|_____.-._____ __/|_________|" );
1069 vRip.emplace_back( " | |" );
1070 iInfoLine = vRip.size();
1071 vRip.emplace_back( " | |" );
1072 vRip.emplace_back( " | <" );
1073 vRip.emplace_back( " | |" );
1074 vRip.emplace_back( " | _ |" );
1075 vRip.emplace_back( " |__/ |" );
1076 vRip.emplace_back( " % / `--. |%" );
1077 vRip.emplace_back( " * .%%| -< @%%%" ); // NOLINT(cata-text-style)
1078 vRip.emplace_back( " `\\%`@| |@@%@%%" );
1079 vRip.emplace_back( " .%%%@@@|% ` % @@@%%@%%%%" );
1080 vRip.emplace_back( " _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%" );
1081
1082 } else {
1083 vRip.emplace_back( " _______ ___" );
1084 vRip.emplace_back( " | \\/ |" );
1085 vRip.emplace_back( " | |" );
1086 vRip.emplace_back( " | |" );
1087 iInfoLine = vRip.size();
1088 vRip.emplace_back( " | |" );
1089 vRip.emplace_back( " | |" );
1090 vRip.emplace_back( " | |" );
1091 vRip.emplace_back( " | |" );
1092 vRip.emplace_back( " | <" );
1093 vRip.emplace_back( " | _ |" );
1094 vRip.emplace_back( " |__/ |" );
1095 vRip.emplace_back( " ______.__%_| |__________ _" );
1096 vRip.emplace_back( " _/ \\| \\" );
1097 iNameLine = vRip.size();
1098 vRip.emplace_back( "| <" );
1099 vRip.emplace_back( "| |" );
1100 iMaxWidth = utf8_width( vRip.back() );
1101 vRip.emplace_back( "| |" );
1102 vRip.emplace_back( "|_____.-._______ __/|__________|" );
1103 vRip.emplace_back( " % / `_-. _ |%" );
1104 vRip.emplace_back( " * .%%| |_) | |_)< @%%%" ); // NOLINT(cata-text-style)
1105 vRip.emplace_back( " `\\%`@| | \\ | | |@@%@%%" );
1106 vRip.emplace_back( " .%%%@@@|% ` % @@@%%@%%%%" );
1107 vRip.emplace_back( " _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%" );
1108 }
1109 } else {
1110 vRip.emplace_back( R"( _________ ____ )" );
1111 vRip.emplace_back( R"( _/ `/ \_ )" );
1112 vRip.emplace_back( R"( _/ _ _ \_. )" );
1113 vRip.emplace_back( R"( _%\ |_) | |_) \_ )" );
1114 vRip.emplace_back( R"( _/ \/ | \ | | \_ )" );
1115 vRip.emplace_back( R"( _/ \_ )" );
1116 vRip.emplace_back( R"(| |)" );
1117 iNameLine = vRip.size();
1118 vRip.emplace_back( R"( ) < )" );
1119 vRip.emplace_back( R"(| |)" );
1120 vRip.emplace_back( R"(| |)" );
1121 vRip.emplace_back( R"(| _ |)" );
1122 vRip.emplace_back( R"(|__/ |)" );
1123 iMaxWidth = utf8_width( vRip.back() );
1124 vRip.emplace_back( R"( / `--. |)" );
1125 vRip.emplace_back( R"(| ( )" );
1126 iInfoLine = vRip.size();
1127 vRip.emplace_back( R"(| |)" );
1128 vRip.emplace_back( R"(| |)" );
1129 vRip.emplace_back( R"(| % . |)" );
1130 vRip.emplace_back( R"(| @` %% |)" );
1131 vRip.emplace_back( R"(| %@%@%\ * %`%@%|)" );
1132 vRip.emplace_back( R"(%%@@@.%@%\%% `\ %%.%%@@%@)" );
1133 vRip.emplace_back( R"(@%@@%%%%%@@@@@@%%%%%%%%@@%%@@@%%%@%%@)" );
1134 }
1135
1136 const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0;
1137 const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0;
1138
1140 point( iOffsetX, iOffsetY ) );
1141 draw_border( w_rip );
1142
1143 sfx::do_player_death_hurt( g->u, true );
1148
1149 for( size_t iY = 0; iY < vRip.size(); ++iY ) {
1150 size_t iX = 0;
1151 const char *str = vRip[iY].data();
1152 for( int slen = vRip[iY].size(); slen > 0; ) {
1153 const uint32_t cTemp = UTF8_getch( &str, &slen );
1154 if( cTemp != U' ' ) {
1155 nc_color ncColor = c_light_gray;
1156
1157 if( cTemp == U'%' ) {
1158 ncColor = c_green;
1159
1160 } else if( cTemp == U'_' || cTemp == U'|' ) {
1161 ncColor = c_white;
1162
1163 } else if( cTemp == U'@' ) {
1164 ncColor = c_brown;
1165
1166 } else if( cTemp == U'*' ) {
1167 ncColor = c_red;
1168 }
1169
1170 mvwputch( w_rip, point( iX + FULL_SCREEN_WIDTH / 2 - ( iMaxWidth / 2 ), iY + 1 ), ncColor,
1171 cTemp );
1172 }
1173 iX += mk_wcwidth( cTemp );
1174 }
1175 }
1176
1177 std::string sTemp;
1178
1179 center_print( w_rip, iInfoLine++, c_white, _( "Survived:" ) );
1180
1182 const int minutes = to_minutes<int>( survived ) % 60;
1183 const int hours = to_hours<int>( survived ) % 24;
1184 const int days = to_days<int>( survived );
1185
1186 if( days > 0 ) {
1187 sTemp = string_format( "%dd %dh %dm", days, hours, minutes );
1188 } else if( hours > 0 ) {
1189 sTemp = string_format( "%dh %dm", hours, minutes );
1190 } else {
1191 sTemp = string_format( "%dm", minutes );
1192 }
1193
1194 center_print( w_rip, iInfoLine++, c_white, sTemp );
1195
1196 const int iTotalKills = get_kill_tracker().monster_kill_count();
1197
1198 sTemp = _( "Kills:" );
1199 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - 5, 1 + iInfoLine++ ), c_light_gray,
1200 ( sTemp + " " ) );
1201 wprintz( w_rip, c_magenta, "%d", iTotalKills );
1202
1203 sTemp = _( "In memory of:" );
1204 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ),
1206 sTemp );
1207
1208 sTemp = u.name;
1209 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ), c_white,
1210 sTemp );
1211
1212 sTemp = _( "Last Words:" );
1213 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ),
1215 sTemp );
1216
1217 int iStartX = FULL_SCREEN_WIDTH / 2 - ( ( iMaxWidth - 4 ) / 2 );
1218 std::string sLastWords = string_input_popup()
1219 .window( w_rip, point( iStartX, iNameLine ), iStartX + iMaxWidth - 4 - 1 )
1220 .max_length( iMaxWidth - 4 - 1 )
1221 .query_string();
1222 death_screen();
1223 const bool is_suicide = uquit == QUIT_SUICIDE;
1224 events().send<event_type::game_over>( is_suicide, sLastWords );
1225 // Struck the save_player_data here to forestall Weirdness
1226 std::string char_filename = generate_memorial_filename( u.name );
1227 move_save_to_graveyard( char_filename );
1228 write_memorial_file( char_filename, sLastWords );
1229 memorial().clear();
1230 std::vector<std::string> characters = list_active_characters();
1231 // remove current player from the active characters list, as they are dead
1232 std::vector<std::string>::iterator curchar = std::find( characters.begin(),
1233 characters.end(), u.name );
1234 if( curchar != characters.end() ) {
1235 characters.erase( curchar );
1236 }
1237
1238 if( characters.empty() ) {
1239 bool queryDelete = false;
1240 bool queryReset = false;
1241
1242 if( get_option<std::string>( "WORLD_END" ) == "query" ) {
1243 bool decided = false;
1244 std::string buffer = _( "Warning: NPC interactions and some other global flags "
1245 "will not all reset when starting a new character in an "
1246 "already-played world. This can lead to some strange "
1247 "behavior.\n\n"
1248 "Are you sure you wish to keep this world?"
1249 );
1250
1251 while( !decided ) {
1252 uilist smenu;
1253 smenu.allow_cancel = false;
1254 smenu.addentry( 0, true, 'r', "%s", _( "Reset world" ) );
1255 smenu.addentry( 1, true, 'd', "%s", _( "Delete world" ) );
1256 smenu.addentry( 2, true, 'k', "%s", _( "Keep world" ) );
1257 smenu.query();
1258
1259 switch( smenu.ret ) {
1260 case 0:
1261 queryReset = true;
1262 decided = true;
1263 break;
1264 case 1:
1265 queryDelete = true;
1266 decided = true;
1267 break;
1268 case 2:
1269 decided = query_yn( buffer );
1270 break;
1271 }
1272 }
1273 }
1274
1275 if( queryDelete || get_option<std::string>( "WORLD_END" ) == "delete" ) {
1276 world_generator->delete_world( world_generator->active_world->world_name, true );
1277
1278 } else if( queryReset || get_option<std::string>( "WORLD_END" ) == "reset" ) {
1279 world_generator->delete_world( world_generator->active_world->world_name, false );
1280 }
1281 } else if( get_option<std::string>( "WORLD_END" ) != "keep" ) {
1282 std::string tmpmessage;
1283 for( auto &character : characters ) {
1284 tmpmessage += "\n ";
1285 tmpmessage += character;
1286 }
1287 popup( _( "World retained. Characters remaining:%s" ), tmpmessage );
1288 }
1289 if( gamemode ) {
1290 gamemode = std::make_unique<special_game>(); // null gamemode or something..
1291 }
1292 }
1293
1294 //Reset any offset due to driving
1296
1297 //clear all sound channels
1303
1304 MAPBUFFER.reset();
1306
1307#if defined(__ANDROID__)
1308 quick_shortcuts_map.clear();
1309#endif
1310 return true;
1311}
uint32_t UTF8_getch(const char **src, int *srclen)
Definition: catacharset.cpp:18
int utf8_width(const char *s, const bool ignore_tags)
std::string name
Definition: character.h:1562
A wrapper over a pointer to a curses window.
Definition: cursesdef.h:55
void send(const cata::event &) const
Definition: event_bus.cpp:58
void move_save_to_graveyard(const std::string &dirname)
Definition: game.cpp:2772
bool save_maps()
Definition: game.cpp:3036
std::unique_ptr< special_game > gamemode
Definition: game.h:1103
void death_screen()
Definition: game.cpp:2722
monster_range all_monsters()
Same as all_creatures but iterators only over monsters.
Definition: game.cpp:12506
bool save_factions_missions_npcs()
Definition: game.cpp:3022
void despawn_monster(monster &critter)
Despawn a specific monster, it's stored on the overmap.
Definition: game.cpp:11532
const kill_tracker & get_kill_tracker() const
Definition: game.cpp:965
void write_memorial_file(const std::string &filename, std::string sLastWords)
Writes information about the character out to a text file timestamped with the time of the file was m...
Definition: game.cpp:3135
std::vector< std::string > list_active_characters()
Returns a list of currently active character saves.
Definition: game.cpp:3120
bool save_artifacts()
Definition: game.cpp:3030
memorial_logger & memorial()
Definition: game.cpp:3085
void reset_npc_dispositions()
Definition: game.cpp:2994
int monster_kill_count() const
string_input_popup & max_length(int value)
Maximal amount of Unicode characters that can be given by the user.
const std::string & query_string(bool loop=true, bool draw_only=false)
string_input_popup & window(const catacurses::window &w, const point &start, int endx)
Set the window area where to display the input text.
A duration defined as a number of specific time units.
Definition: calendar.h:180
bool allow_cancel
Definition: ui.h:362
bool has_amount(const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
Check instance provides at least qty of an item (.
Definition: visitable.cpp:1088
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_magenta
Definition: color.h:25
#define c_brown
Definition: color.h:26
#define c_red
Definition: color.h:21
static const itype_id itype_holybook_bible1("holybook_bible1")
static std::string generate_memorial_filename(const std::string &char_name)
Definition: game.cpp:1000
static const itype_id itype_holybook_bible2("holybook_bible2")
static const itype_id itype_holybook_bible3("holybook_bible3")
@ QUIT_DIED
Definition: game.h:72
@ QUIT_SUICIDE
Definition: game.h:69
const time_point & start_of_cataclysm
Definition: calendar.cpp:33
window newwin(int nlines, int ncols, const point &begin)
Definition: ncurses_def.cpp:34
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
const size_t size
Definition: omdata.h:62
void do_player_death_hurt(const player &target, bool death)
Definition: sounds.cpp:1624
void fade_audio_channel(channel channel, int duration)
Definition: sounds.cpp:1609
void fade_audio_group(group group, int duration)
Definition: sounds.cpp:1608
int TERMX
Definition: output.cpp:47
void mvwprintz(const catacurses::window &w, const point &p, const nc_color &FG, const std::string &text)
Definition: output.cpp:2035
int FULL_SCREEN_HEIGHT
Definition: output.cpp:56
int TERMY
Definition: output.cpp:48
void center_print(const catacurses::window &w, const int y, const nc_color &FG, const std::string &text)
Definition: output.cpp:446
void wprintz(const catacurses::window &w, const nc_color &FG, const std::string &text)
Definition: output.cpp:2043
int FULL_SCREEN_WIDTH
Definition: output.cpp:55
void mvwputch(const catacurses::window &w, const point &p, nc_color FG, int ch)
Definition: output.cpp:477
void draw_border(const catacurses::window &w, nc_color border_color, const std::string &title, nc_color title_color)
Definition: output.cpp:575
int mk_wcwidth(uint32_t ucs)
Definition: wcwidth.cpp:94

References _, uilist::addentry(), all_monsters(), uilist::allow_cancel, sfx::any, c_brown, c_green, c_light_gray, c_magenta, c_red, c_white, center_print(), memorial_logger::clear(), overmapbuffer::clear(), sfx::context_themes, death_screen(), despawn_monster(), sfx::do_player_death_hurt(), draw_border(), events(), sfx::fade_audio_channel(), sfx::fade_audio_group(), sfx::fatigue, detail::find(), FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, g, game_over, gamemode, generate_memorial_filename(), get_kill_tracker(), visitable< T >::has_amount(), Character::has_trait(), itype_holybook_bible1, itype_holybook_bible2, itype_holybook_bible3, list_active_characters(), MAPBUFFER, string_input_popup::max_length(), memorial(), mk_wcwidth(), kill_tracker::monster_kill_count(), move_save_to_graveyard(), mvwprintz(), mvwputch(), Character::name, catacurses::newwin(), overmap_buffer, point_zero, popup(), uilist::query(), string_input_popup::query_string(), query_yn(), QUIT_DIED, QUIT_SUICIDE, mapbuffer::reset(), reset_npc_dispositions(), uilist::ret, save_artifacts(), save_factions_missions_npcs(), save_maps(), event_bus::send(), set_driving_view_offset(), om_direction::size, calendar::start_of_cataclysm, string_format(), TERMX, TERMY, sfx::time_of_day, calendar::turn, u, uquit, UTF8_getch(), utf8_width(), sfx::weather, string_input_popup::window(), world_generator, wprintz(), and write_memorial_file().

Referenced by do_turn().

◆ cleanup_dead()

void game::cleanup_dead ( )

Definition at line 4361 of file game.cpp.

4362{
4363 // Dead monsters need to stay in the tracker until everything else that needs to die does so
4364 // This is because dying monsters can still interact with other dying monsters (@ref Creature::killer)
4365 bool monster_is_dead = critter_tracker->kill_marked_for_death();
4366
4367 bool npc_is_dead = false;
4368 // can't use all_npcs as that does not include dead ones
4369 for( const auto &n : active_npc ) {
4370 if( n->is_dead() ) {
4371 n->die( nullptr ); // make sure this has been called to create corpses etc.
4372 npc_is_dead = true;
4373 }
4374 }
4375
4376 if( monster_is_dead ) {
4377 // From here on, pointers to creatures get invalidated as dead creatures get removed.
4378 critter_tracker->remove_dead();
4379 }
4380
4381 if( npc_is_dead ) {
4382 for( auto it = active_npc.begin(); it != active_npc.end(); ) {
4383 if( ( *it )->is_dead() ) {
4384 remove_npc_follower( ( *it )->getID() );
4385 overmap_buffer.remove_npc( ( *it )->getID() );
4386 it = active_npc.erase( it );
4387 } else {
4388 it++;
4389 }
4390 }
4391 }
4392
4393 critter_died = false;
4394}
void remove_npc_follower(const character_id &id)
Remove follower id from follower set.
Definition: game.cpp:1962
pimpl< Creature_tracker > critter_tracker
Definition: game.h:1021
std::list< shared_ptr_fast< npc > > active_npc
Definition: game.h:1085
bool critter_died
Has anything died in this turn and needs to be cleaned up?
Definition: game.h:1097
shared_ptr_fast< npc > remove_npc(const character_id &id)
Find npc by id and if found, erase it from the npc list and return it ( or return nullptr if not foun...

References active_npc, critter_died, critter_tracker, overmap_buffer, overmapbuffer::remove_npc(), and remove_npc_follower().

Referenced by do_turn(), and monmove().

◆ clear_zombies()

void game::clear_zombies ( )

Redirects to the creature_tracker clear() function.

Definition at line 5027 of file game.cpp.

5028{
5029 critter_tracker->clear();
5030}

References critter_tracker.

Referenced by setup().

◆ control_vehicle()

void game::control_vehicle ( )
private

Definition at line 5441 of file game.cpp.

5442{
5443 static const itype_id fuel_type_animal( "animal" );
5444 int veh_part = -1;
5445 vehicle *veh = remoteveh();
5446 if( veh == nullptr ) {
5447 if( const optional_vpart_position vp = m.veh_at( u.pos() ) ) {
5448 veh = &vp->vehicle();
5449 veh_part = vp->part_index();
5450 }
5451 }
5452 if( veh != nullptr && veh->player_in_control( u ) &&
5453 veh->avail_part_with_feature( veh_part, "CONTROLS", true ) >= 0 ) {
5454 veh->use_controls( u.pos() );
5455 } else if( veh && veh->player_in_control( u ) &&
5456 veh->avail_part_with_feature( veh_part, "CONTROL_ANIMAL", true ) >= 0 ) {
5457 u.controlling_vehicle = false;
5458 add_msg( m_info, _( "You let go of the reins." ) );
5459 } else if( veh && ( veh->avail_part_with_feature( veh_part, "CONTROLS", true ) >= 0 ||
5460 ( veh->avail_part_with_feature( veh_part, "CONTROL_ANIMAL", true ) >= 0 &&
5461 veh->has_engine_type( fuel_type_animal, false ) && veh->has_harnessed_animal() ) ) &&
5462 u.in_vehicle ) {
5463 if( u.has_trait( trait_WAYFARER ) ) {
5464 add_msg( m_info, _( "You refuse to take control of this vehicle." ) );
5465 return;
5466 }
5467 if( !veh->interact_vehicle_locked() ) {
5468 veh->handle_potential_theft( dynamic_cast<player &>( u ) );
5469 return;
5470 }
5471 if( veh->engine_on ) {
5472 if( !veh->handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
5473 return;
5474 }
5475 u.controlling_vehicle = true;
5476 add_msg( _( "You take control of the %s." ), veh->name );
5477 } else {
5478 if( !veh->handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
5479 return;
5480 }
5481 veh->start_engines( true );
5482 }
5483 } else { // Start looking for nearby vehicle controls.
5484 int num_valid_controls = 0;
5485 cata::optional<tripoint> vehicle_position;
5486 cata::optional<vpart_reference> vehicle_controls;
5487 for( const tripoint elem : m.points_in_radius( g->u.pos(), 1 ) ) {
5488 if( const optional_vpart_position vp = m.veh_at( elem ) ) {
5489 const cata::optional<vpart_reference> controls = vp.value().part_with_feature( "CONTROLS", true );
5490 if( controls ) {
5491 num_valid_controls++;
5492 vehicle_position = elem;
5493 vehicle_controls = controls;
5494 }
5495 }
5496 }
5497 if( num_valid_controls < 1 ) {
5498 add_msg( _( "No vehicle controls found." ) );
5499 return;
5500 } else if( num_valid_controls > 1 ) {
5501 vehicle_position = choose_adjacent( _( "Control vehicle where?" ) );
5502 if( !vehicle_position ) {
5503 return;
5504 }
5505 const optional_vpart_position vp = m.veh_at( *vehicle_position );
5506 if( vp ) {
5507 vehicle_controls = vp.value().part_with_feature( "CONTROLS", true );
5508 if( !vehicle_controls ) {
5509 add_msg( _( "The vehicle doesn't have controls there." ) );
5510 return;
5511 }
5512 } else {
5513 add_msg( _( "No vehicle there." ) );
5514 return;
5515 }
5516 }
5517 // If we hit neither of those, there's only one set of vehicle controls, which should already have been found.
5518 if( vehicle_controls ) {
5519 veh = &vehicle_controls->vehicle();
5520 if( !veh->handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
5521 return;
5522 }
5523 veh->use_controls( *vehicle_position );
5524 //May be folded up (destroyed), so need to re-get it
5525 veh = g->remoteveh();
5526 }
5527 }
5528 if( veh ) {
5529 // If we reached here, we gained control of a vehicle.
5530 // Clear the map memory for the area covered by the vehicle to eliminate ghost vehicles.
5531 for( const tripoint &target : veh->get_points() ) {
5532 u.clear_memorized_tile( m.getabs( target ) );
5533 }
5534 veh->is_following = false;
5535 veh->is_patrolling = false;
5536 veh->autopilot_on = false;
5537 veh->is_autodriving = false;
5538 }
5539}
cata::optional< tripoint > choose_adjacent(const std::string &message, const bool allow_vertical)
Request player input of adjacent tile, possibly including vertical tiles.
Definition: action.cpp:1006
bool in_vehicle
Definition: character.h:1569
void clear_memorized_tile(const tripoint &pos)
Definition: avatar.cpp:163
vehicle * remoteveh()
Returns the current remotely controlled vehicle.
Definition: game.cpp:2558
tripoint_range< tripoint > points_in_radius(const tripoint &center, size_t radius, size_t radiusz=0) const
Definition: map.cpp:8390
optional_vpart_position veh_at(const tripoint &p) const
Checks if tile is occupied by vehicle and by which part.
Definition: map.cpp:988
Simple wrapper to forward functions that may return a cata::optional to vpart_position.
Definition: player.h:99
bool engine_on
Definition: vehicle.h:1930
std::set< tripoint > & get_points(bool force_refresh=false)
Definition: vehicle.cpp:6568
bool handle_potential_theft(player &p, bool check_only=false, bool prompt=true)
Definition: vehicle.cpp:4197
std::string name
Definition: vehicle.h:1792
bool has_engine_type(const itype_id &ft, bool enabled) const
Definition: vehicle.cpp:1031
void start_engines(bool take_control=false, bool autodrive=false)
void use_controls(const tripoint &pos)
Operate vehicle controls.
vehicle(const vproto_id &type_id, int init_veh_fuel=-1, int init_veh_status=-1)
Definition: vehicle.cpp:251
bool has_harnessed_animal() const
bool interact_vehicle_locked()
int avail_part_with_feature(int p, const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2543
bool autopilot_on
Definition: vehicle.h:1938
bool is_autodriving
Definition: vehicle.h:1923
cata::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2459
static const trait_id trait_WAYFARER("WAYFARER")

References _, add_msg(), vehicle::autopilot_on, vehicle::avail_part_with_feature(), choose_adjacent(), avatar::clear_memorized_tile(), Character::controlling_vehicle, vehicle::engine_on, fuel_type_animal, g, vehicle::get_points(), map::getabs(), vehicle::handle_potential_theft(), vehicle::has_engine_type(), vehicle::has_harnessed_animal(), Character::has_trait(), Character::in_vehicle, vehicle::interact_vehicle_locked(), vehicle::is_autodriving, vehicle::is_following, vehicle::is_patrolling, m, m_info, vehicle::name, vpart_position::part_with_feature(), vehicle::player_in_control(), map::points_in_radius(), Character::pos(), remoteveh(), vehicle::start_engines(), trait_WAYFARER, u, vehicle::use_controls(), cata::optional< T >::value(), map::veh_at(), and vehicle::vehicle().

Referenced by handle_action().

◆ create_or_get_main_ui_adaptor()

shared_ptr_fast< ui_adaptor > game::create_or_get_main_ui_adaptor ( )

In tiles mode w_terrain can have a different font (with a different tile dimension) or can be drawn by cata_tiles which uses tiles that again might have a different dimension then the normal font used everywhere else.

TERRAIN_WINDOW_WIDTH/TERRAIN_WINDOW_HEIGHT defines how many squares can be displayed in w_terrain (using it's specific tile dimension), not including partially drawn squares at the right/bottom. You should use it whenever you want to draw specific squares in that window or to determine whether a specific square is draw on screen (or outside the screen and needs scrolling).

TERRAIN_WINDOW_TERM_WIDTH/TERRAIN_WINDOW_TERM_HEIGHT defines the size of w_terrain in the standard font dimension (the font that everything else uses). You usually don't have to use it, expect for positioning of windows, because the window positions use the standard font dimension.

The code here calculates size available for w_terrain, caps it at max_view_size (the maximal view range than any character can have at any time). It is stored in TERRAIN_WINDOW_*.

Definition at line 3272 of file game.cpp.

3273{
3275 if( !ui ) {
3276 main_ui_adaptor = ui = make_shared_fast<ui_adaptor>();
3277 ui->on_redraw( []( const ui_adaptor & ) {
3278 g->draw();
3279 } );
3280 ui->on_screen_resize( [this]( ui_adaptor & ui ) {
3281 // remove some space for the sidebar, this is the maximal space
3282 // (using standard font) that the terrain window can have
3283 const int sidebar_left = panel_manager::get_manager().get_width_left();
3284 const int sidebar_right = panel_manager::get_manager().get_width_right();
3285
3287 TERRAIN_WINDOW_WIDTH = TERMX - ( sidebar_left + sidebar_right );
3290
3291 /**
3292 * In tiles mode w_terrain can have a different font (with a different
3293 * tile dimension) or can be drawn by cata_tiles which uses tiles that again
3294 * might have a different dimension then the normal font used everywhere else.
3295 *
3296 * TERRAIN_WINDOW_WIDTH/TERRAIN_WINDOW_HEIGHT defines how many squares can
3297 * be displayed in w_terrain (using it's specific tile dimension), not
3298 * including partially drawn squares at the right/bottom. You should
3299 * use it whenever you want to draw specific squares in that window or to
3300 * determine whether a specific square is draw on screen (or outside the screen
3301 * and needs scrolling).
3302 *
3303 * TERRAIN_WINDOW_TERM_WIDTH/TERRAIN_WINDOW_TERM_HEIGHT defines the size of
3304 * w_terrain in the standard font dimension (the font that everything else uses).
3305 * You usually don't have to use it, expect for positioning of windows,
3306 * because the window positions use the standard font dimension.
3307 *
3308 * The code here calculates size available for w_terrain, caps it at
3309 * max_view_size (the maximal view range than any character can have at
3310 * any time).
3311 * It is stored in TERRAIN_WINDOW_*.
3312 */
3314
3315 // Position of the player in the terrain window, it is always in the center
3318
3320 point( sidebar_left, 0 ) );
3321
3322 // minimap is always MINIMAP_WIDTH x MINIMAP_HEIGHT in size
3324
3325 // need to init in order to avoid crash. gets updated by the panel code.
3327
3328 ui.position_from_window( catacurses::stdscr );
3329 } );
3330 ui->mark_resize();
3331 }
3332 return ui;
3333}
catacurses::window w_pixel_minimap
Definition: game.h:1039
catacurses::window w_minimap_ptr
Definition: game.h:1076
weak_ptr_fast< ui_adaptor > main_ui_adaptor
Definition: game.h:1122
catacurses::window w_minimap
Definition: game.h:1038
catacurses::window w_terrain_ptr
Definition: game.h:1075
static panel_manager & get_manager()
Definition: panels.h:72
int get_width_right()
Definition: panels.cpp:2289
int get_width_left()
Definition: panels.cpp:2297
static constexpr int MINIMAP_WIDTH
static constexpr int MINIMAP_HEIGHT
void to_map_font_dimension(int &, int &)
Definition: game_ui.cpp:20
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16
window stdscr
int TERRAIN_WINDOW_TERM_WIDTH
Definition: output.cpp:53
int TERRAIN_WINDOW_TERM_HEIGHT
Definition: output.cpp:54
int POSX
Definition: output.cpp:49
int TERRAIN_WINDOW_WIDTH
Definition: output.cpp:51
int POSY
Definition: output.cpp:50
int TERRAIN_WINDOW_HEIGHT
Definition: output.cpp:52

References g, panel_manager::get_manager(), panel_manager::get_width_left(), panel_manager::get_width_right(), main_ui_adaptor, MINIMAP_HEIGHT, MINIMAP_WIDTH, catacurses::newwin(), point_zero, POSX, POSY, catacurses::stdscr, TERMX, TERMY, TERRAIN_WINDOW_HEIGHT, TERRAIN_WINDOW_TERM_HEIGHT, TERRAIN_WINDOW_TERM_WIDTH, TERRAIN_WINDOW_WIDTH, to_map_font_dimension(), w_minimap, w_minimap_ptr, w_pixel_minimap, w_terrain, and w_terrain_ptr.

◆ create_starting_npcs()

void game::create_starting_npcs ( )
private

Definition at line 970 of file game.cpp.

971{
972 if( !get_option<bool>( "STATIC_NPC" ) ||
973 get_option<std::string>( "STARTING_NPC" ) == "never" ) {
974 return; //Do not generate a starting npc.
975 }
976
977 //We don't want more than one starting npc per starting location
978 const int radius = 1;
979 if( !overmap_buffer.get_npcs_near_player( radius ).empty() ) {
980 return; //There is already an NPC in this starting location
981 }
982
983 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
984 tmp->normalize();
985 tmp->randomize( one_in( 2 ) ? NC_DOCTOR : NC_NONE );
986 tmp->spawn_at_precise( { get_levx(), get_levy() }, u.pos() - point_south_east );
988 tmp->form_opinion( u );
989 tmp->set_attitude( NPCATT_NULL );
990 //This sets the NPC mission. This NPC remains in the starting location.
991 tmp->mission = NPC_MISSION_SHELTER;
992 tmp->chatbin.first_topic = "TALK_SHELTER";
993 tmp->toggle_trait( trait_id( "NPC_STARTING_NPC" ) );
994 tmp->set_fac( faction_id( "no_faction" ) );
995 //One random starting NPC mission
996 tmp->add_new_mission( mission::reserve_random( ORIGIN_OPENER_NPC, tmp->global_omt_location(),
997 tmp->getID() ) );
998}
int get_levy() const
Definition: game.cpp:12396
int get_levx() const
The top left corner of the reality bubble (in submaps coordinates).
Definition: game.cpp:12391
static mission * reserve_random(mission_origin origin, const tripoint_abs_omt &p, const character_id &npc_id)
Definition: mission.cpp:200
std::vector< shared_ptr_fast< npc > > get_npcs_near_player(int radius)
Same as get_npcs_near(int,int,int,int) but uses player position as center.
void insert_npc(const shared_ptr_fast< npc > &who)
Adds the npc to an overmap ( based on the npcs current location ) and stores it there.
string_id< faction > faction_id
Definition: clzones.h:30
@ ORIGIN_OPENER_NPC
Definition: mission.h:46
@ NPCATT_NULL
Definition: npc.h:81
@ NPC_MISSION_SHELTER
Definition: npc.h:181
npc_class_id NC_NONE("NC_NONE")
npc_class_id NC_DOCTOR("NC_DOCTOR")
static constexpr point point_south_east
Definition: point.h:279
bool one_in(int chance)
Definition: rng.cpp:65

References get_levx(), get_levy(), overmapbuffer::get_npcs_near_player(), overmapbuffer::insert_npc(), NC_DOCTOR, NC_NONE, NPC_MISSION_SHELTER, NPCATT_NULL, one_in(), ORIGIN_OPENER_NPC, overmap_buffer, point_south_east, Character::pos(), mission::reserve_random(), trait_id, and u.

Referenced by start_game().

◆ critter_at() [1/2]

template<typename T >
T * game::critter_at ( const tripoint p,
bool  allow_hallucination = false 
)

Returns the Creature at the given location.

Optionally casted to the given type of creature: npc, player, monster - if there is a creature, but it's not of the requested type, returns nullptr.

Parameters
allow_hallucinationWhether to return monsters that are actually hallucinations.

Definition at line 4832 of file game.cpp.

4833{
4834 if( const shared_ptr_fast<monster> mon_ptr = critter_tracker->find( p ) ) {
4835 if( !allow_hallucination && mon_ptr->is_hallucination() ) {
4836 return nullptr;
4837 }
4838 // if we wanted to check for an NPC / player / avatar,
4839 // there is sometimes a monster AND an NPC/player there at the same time.
4840 // because the NPC/player etc may be riding that monster.
4841 // so only return the monster if we were actually looking for a monster.
4842 // otherwise, keep looking for the rider.
4843 // critter_at<creature> or critter_at() with no template will still default to returning monster first,
4844 // which is ok for the occasions where that happens.
4845 if( !mon_ptr->has_effect( effect_ridden ) || ( std::is_same<T, monster>::value ||
4846 std::is_same<T, Creature>::value || std::is_same<T, const monster>::value ||
4847 std::is_same<T, const Creature>::value ) ) {
4848 return dynamic_cast<T *>( mon_ptr.get() );
4849 }
4850 }
4851 if( !std::is_same<T, npc>::value && !std::is_same<T, const npc>::value ) {
4852 if( p == u.pos() ) {
4853 return dynamic_cast<T *>( &u );
4854 }
4855 }
4856 for( auto &cur_npc : active_npc ) {
4857 if( cur_npc->pos() == p && !cur_npc->is_dead() ) {
4858 return dynamic_cast<T *>( cur_npc.get() );
4859 }
4860 }
4861 return nullptr;
4862}
static const efftype_id effect_ridden("ridden")

References active_npc, critter_tracker, effect_ridden, Character::pos(), and u.

Referenced by draw_look_around_cursor(), examine(), find_or_make_stairs(), fling_creature(), forced_door_closing(), get_player_input(), is_empty(), knockback(), phasing_move(), print_all_tile_info(), spawn_hallucination(), swap_critters(), and update_stair_monsters().

◆ critter_at() [2/2]

template<typename T >
const T * game::critter_at ( const tripoint p,
bool  allow_hallucination = false 
) const

Definition at line 4865 of file game.cpp.

4866{
4867 return const_cast<game *>( this )->critter_at<T>( p, allow_hallucination );
4868}
Definition: game.h:144

◆ critter_by_id()

template<typename T >
template Creature * game::critter_by_id< Creature > ( const character_id id)
Returns
The living creature with the given id. Returns null if no living creature with such an id exists. Never returns a dead creature. Currently only the player character and npcs have ids.

Definition at line 4911 of file game.cpp.

4912{
4913 if( id == u.getID() ) {
4914 // player is always alive, therefore no is-dead check
4915 return dynamic_cast<T *>( &u );
4916 }
4917 return find_npc( id );
4918}
character_id getID() const
Definition: character.cpp:465
npc * find_npc(character_id id)
Find the npc with the given ID.
Definition: game.cpp:1951

References find_npc(), Character::getID(), and u.

◆ death_screen()

void game::death_screen ( )
private

Definition at line 2722 of file game.cpp.

2723{
2724 gamemode->game_over();
2728 follower_ids.clear();
2730}
stats_tracker & stats()
Definition: game.cpp:3080
void disp_NPC_epilogues()
Definition: game.cpp:3159
void display_faction_epilogues()
Definition: game.cpp:3176
void display_messages()
Definition: messages.cpp:801
void show_scores_ui(const achievements_tracker &achievements, stats_tracker &stats, const kill_tracker &kills)
Definition: scores_ui.cpp:69

References achievements_tracker_ptr, disp_NPC_epilogues(), display_faction_epilogues(), Messages::display_messages(), follower_ids, gamemode, get_kill_tracker(), show_scores_ui(), and stats().

Referenced by cleanup_at_end().

◆ despawn_monster()

void game::despawn_monster ( monster critter)

Despawn a specific monster, it's stored on the overmap.

Also removes it from the creature tracker. Keep in mind that any monster index may point to a different monster after calling this (or to no monster at all).

Definition at line 11532 of file game.cpp.

11533{
11534 if( !critter.is_hallucination() ) {
11535 // hallucinations aren't stored, they come and go as they like,
11537 }
11538
11539 critter.on_unload();
11540 remove_zombie( critter );
11541 // simulate it being dead so further processing of it (e.g. in monmove) will yield
11542 critter.set_hp( 0 );
11543}
void remove_zombie(const monster &critter)
Definition: game.cpp:5022
bool is_hallucination() const override
Definition: monster.cpp:2648
void on_unload()
Do some cleanup and caching as monster is being unloaded from map.
Definition: monster.cpp:2980
void set_hp(int hp)
Directly set the current hp of the monster (not capped at the maximal hp).
Definition: monster.cpp:1631
void despawn_monster(const monster &critter)
Despawn the monster back onto the overmap.

References overmapbuffer::despawn_monster(), monster::is_hallucination(), monster::on_unload(), overmap_buffer, remove_zombie(), and monster::set_hp().

Referenced by cleanup_at_end(), monmove(), place_player_overmap(), and shift_monsters().

◆ disable_robot()

bool game::disable_robot ( const tripoint p)

If there is a robot (that can be disabled), query the player and try to disable it.

Returns
true if the robot has been disabled or a similar action has been done. false if the player did not choose any action and the function has effectively done nothing.

Definition at line 9180 of file game.cpp.

9181{
9182 monster *const mon_ptr = critter_at<monster>( p );
9183 if( !mon_ptr ) {
9184 return false;
9185 }
9186 monster &critter = *mon_ptr;
9187 if( critter.friendly == 0 || critter.has_flag( MF_RIDEABLE_MECH ) ||
9188 ( critter.has_flag( MF_PAY_BOT ) && critter.has_effect( effect_paid ) ) ) {
9189 // Can only disable / reprogram friendly monsters
9190 return false;
9191 }
9192 const auto mid = critter.type->id;
9193 const auto mon_item_id = critter.type->revert_to_itype;
9194 if( !mon_item_id.is_empty() &&
9195 query_yn( _( "Deactivate the %s?" ), critter.name() ) ) {
9196
9197 u.moves -= 100;
9198 m.add_item_or_charges( p, critter.to_item() );
9199 if( !critter.has_flag( MF_INTERIOR_AMMO ) ) {
9200 for( auto &ammodef : critter.ammo ) {
9201 if( ammodef.second > 0 ) {
9202 m.spawn_item( p.xy(), ammodef.first, 1, ammodef.second, calendar::turn );
9203 }
9204 }
9205 }
9206 remove_zombie( critter );
9207 return true;
9208 }
9209 // Manhacks are special, they have their own menu here.
9210 if( mid == mon_manhack ) {
9211 int choice = UILIST_CANCEL;
9212 if( critter.has_effect( effect_docile ) ) {
9213 choice = uilist( _( "Reprogram the manhack?" ), { _( "Engage targets." ) } );
9214 } else {
9215 choice = uilist( _( "Reprogram the manhack?" ), { _( "Follow me." ) } );
9216 }
9217 switch( choice ) {
9218 case 0:
9219 if( critter.has_effect( effect_docile ) ) {
9220 critter.remove_effect( effect_docile );
9221 if( one_in( 3 ) ) {
9222 add_msg( _( "The %s hovers momentarily as it surveys the area." ),
9223 critter.name() );
9224 }
9225 } else {
9226 critter.add_effect( effect_docile, 1_turns, num_bp );
9227 if( one_in( 3 ) ) {
9228 add_msg( _( "The %s lets out a whirring noise and starts to follow you." ),
9229 critter.name() );
9230 }
9231 }
9232 u.moves -= 100;
9233 return true;
9234 default:
9235 break;
9236 }
9237 }
9238 return false;
9239}
@ num_bp
Definition: bodypart.h:52
bool remove_effect(const efftype_id &eff_id, body_part bp=num_bp)
Removes a listed effect.
Definition: creature.cpp:1130
void spawn_item(const tripoint &p, const itype_id &type_id, unsigned quantity=1, int charges=0, const time_point &birthday=calendar::start_of_cataclysm, int damlevel=0)
Definition: map.cpp:4181
bool has_flag(m_flag f) const override
Definition: monster.cpp:869
item to_item() const
Convert this monster into an item (see mtype::revert_to_itype).
Definition: monster.cpp:2788
void add_effect(const efftype_id &eff_id, const time_duration &dur, const bodypart_str_id &bp, int intensity=0, bool force=false, bool deferred=false) override
Performs any monster-specific modifications to the arguments before passing to Creature::add_effect()...
Definition: monster.cpp:1807
int friendly
Definition: monster.h:471
std::string name(unsigned int quantity=1) const
Definition: monster.cpp:492
std::map< itype_id, int > ammo
Definition: monster.h:512
static const efftype_id effect_docile("docile")
static const efftype_id effect_paid("paid")
static const mtype_id mon_manhack("mon_manhack")
@ MF_INTERIOR_AMMO
Definition: mtype.h:146
@ MF_RIDEABLE_MECH
Definition: mtype.h:115
@ MF_PAY_BOT
Definition: mtype.h:121
itype_id revert_to_itype
If this is not empty, the monster can be converted into an item of this type (if it's friendly).
Definition: mtype.h:361
constexpr point xy() const
Definition: point.h:220
const int UILIST_CANCEL
Definition: ui.h:28

References _, monster::add_effect(), map::add_item_or_charges(), add_msg(), monster::ammo, effect_docile, effect_paid, monster::friendly, Creature::has_effect(), monster::has_flag(), mtype::id, m, MF_INTERIOR_AMMO, MF_PAY_BOT, MF_RIDEABLE_MECH, mon_manhack, Creature::moves, monster::name(), num_bp, one_in(), query_yn(), Creature::remove_effect(), remove_zombie(), mtype::revert_to_itype, map::spawn_item(), monster::to_item(), calendar::turn, monster::type, u, UILIST_CANCEL, and tripoint::xy().

Referenced by examine().

◆ disp_NPC_epilogues()

void game::disp_NPC_epilogues ( )
private

Definition at line 3159 of file game.cpp.

3160{
3161 // TODO: This search needs to be expanded to all NPCs
3162 for( auto elem : follower_ids ) {
3164 if( !guy ) {
3165 continue;
3166 }
3167 const auto new_win = []() {
3169 point( std::max( 0, ( TERMX - FULL_SCREEN_WIDTH ) / 2 ),
3170 std::max( 0, ( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) ) );
3171 };
3172 scrollable_text( new_win, guy->disp_name(), guy->get_epilogue() );
3173 }
3174}
shared_ptr_fast< npc > find_npc(character_id id)
Find the npc with the given ID.
void scrollable_text(const std::function< catacurses::window()> &init_window, const std::string &title, const std::string &text)
Definition: output.cpp:352

References overmapbuffer::find_npc(), follower_ids, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, catacurses::newwin(), overmap_buffer, scrollable_text(), TERMX, and TERMY.

Referenced by death_screen().

◆ disp_NPCs()

void game::disp_NPCs ( )

Definition at line 3210 of file game.cpp.

3211{
3212 const tripoint_abs_omt ppos = u.global_omt_location();
3213 const tripoint &lpos = u.pos();
3214 std::vector<shared_ptr_fast<npc>> npcs = overmap_buffer.get_npcs_near_player( 100 );
3215 std::sort( npcs.begin(), npcs.end(), npc_dist_to_player() );
3216
3218 ui_adaptor ui;
3219 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
3222 TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ) );
3223 ui.position_from_window( w );
3224 } );
3225 ui.mark_resize();
3226 ui.on_redraw( [&]( const ui_adaptor & ) {
3227 werase( w );
3228 mvwprintz( w, point_zero, c_white, _( "Your overmap position: %s" ), ppos.to_string() );
3229 // NOLINTNEXTLINE(cata-use-named-point-constants)
3230 mvwprintz( w, point( 0, 1 ), c_white, _( "Your local position: %s" ), lpos.to_string() );
3231 size_t i;
3232 for( i = 0; i < 20 && i < npcs.size(); i++ ) {
3233 const tripoint_abs_omt apos = npcs[i]->global_omt_location();
3234 mvwprintz( w, point( 0, i + 3 ), c_white, "%s: %s", npcs[i]->name,
3235 apos.to_string() );
3236 }
3237 for( const monster &m : all_monsters() ) {
3238 mvwprintz( w, point( 0, i + 3 ), c_white, "%s: %d, %d, %d", m.name(),
3239 m.posx(), m.posy(), m.posz() );
3240 ++i;
3241 }
3242 wnoutrefresh( w );
3243 } );
3244
3245 input_context ctxt( "DISP_NPCS" );
3246 ctxt.register_action( "CONFIRM" );
3247 ctxt.register_action( "QUIT" );
3248 ctxt.register_action( "HELP_KEYBINDINGS" );
3249 bool stop = false;
3250 while( !stop ) {
3252 const std::string action = ctxt.handle_input();
3253 if( action == "CONFIRM" || action == "QUIT" ) {
3254 stop = true;
3255 }
3256 }
3257}
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6208
std::string to_string() const
Definition: coordinates.h:140
Represents a context in which a set of actions can be performed.
Definition: input.h:382
std::string name(const tripoint &p)
Definition: map.cpp:1336
void wnoutrefresh(const window &win)
Definition: ncurses_def.cpp:43
void werase(const window &win)
Definition: ncurses_def.cpp:53
std::string to_string() const
Definition: point.cpp:16

References _, action, all_monsters(), c_white, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, overmapbuffer::get_npcs_near_player(), Character::global_omt_location(), input_context::handle_input(), m, mvwprintz(), map::name(), om_direction::name(), catacurses::newwin(), overmap_buffer, point_zero, Character::pos(), ui_manager::redraw(), input_context::register_action(), TERMX, TERMY, coords::coord_point< Point, Origin, Scale >::to_string(), tripoint::to_string(), u, catacurses::werase(), and catacurses::wnoutrefresh().

◆ display_faction_epilogues()

void game::display_faction_epilogues ( )
private

Definition at line 3176 of file game.cpp.

3177{
3178 for( const auto &elem : faction_manager_ptr->all() ) {
3179 if( elem.second.known_by_u ) {
3180 const std::vector<std::string> epilogue = elem.second.epilogue();
3181 if( !epilogue.empty() ) {
3182 const auto new_win = []() {
3184 point( std::max( 0, ( TERMX - FULL_SCREEN_WIDTH ) / 2 ),
3185 std::max( 0, ( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) ) );
3186 };
3187 scrollable_text( new_win, elem.second.name,
3188 std::accumulate( epilogue.begin() + 1, epilogue.end(), epilogue.front(),
3189 []( const std::string & lhs, const std::string & rhs ) -> std::string {
3190 return lhs + "\n" + rhs;
3191 } ) );
3192 }
3193 }
3194 }
3195}
pimpl< faction_manager > faction_manager_ptr
Definition: game.h:1022

References faction_manager_ptr, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, catacurses::newwin(), scrollable_text(), TERMX, and TERMY.

Referenced by death_screen().

◆ display_lighting()

void game::display_lighting ( )
private

Definition at line 11744 of file game.cpp.

11745{
11746 if( use_tiles ) {
11748 if( !g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) {
11749 return;
11750 }
11751 uilist lighting_menu;
11752 std::vector<std::string> lighting_menu_strings{
11753 "Global lighting conditions"
11754 };
11755
11756 int count = 0;
11757 for( const auto &menu_str : lighting_menu_strings ) {
11758 lighting_menu.addentry( count++, true, MENU_AUTOASSIGN, "%s", menu_str );
11759 }
11760
11761 lighting_menu.w_y_setup = 0;
11762 lighting_menu.query();
11763 if( ( lighting_menu.ret >= 0 ) &&
11764 ( static_cast<size_t>( lighting_menu.ret ) < lighting_menu_strings.size() ) ) {
11765 g->displaying_lighting_condition = lighting_menu.ret;
11766 }
11767 }
11768}
@ ACTION_DISPLAY_LIGHTING
Toggle lighting conditions map.
Definition: action.h:315
bool use_tiles
Use tiles for display.
void display_toggle_overlay(action_id)
Definition: game.cpp:11640
pos_scalar w_y_setup
Definition: ui.h:338
constexpr size_t count()
Definition: fmtlib_core.h:1073
const int MENU_AUTOASSIGN
Definition: ui.h:31

References ACTION_DISPLAY_LIGHTING, uilist::addentry(), detail::count(), display_toggle_overlay(), g, MENU_AUTOASSIGN, uilist::query(), uilist::ret, use_tiles, and uilist::w_y_setup.

Referenced by handle_action(), and look_around().

◆ display_overlay_state()

bool game::display_overlay_state ( action_id  action)

Definition at line 11635 of file game.cpp.

11636{
11638}
cata::optional< action_id > displaying_overlays
Definition: game.h:967

References action, and displaying_overlays.

Referenced by display_toggle_overlay(), and display_visibility().

◆ display_radiation()

void game::display_radiation ( )
private

Definition at line 11770 of file game.cpp.

11771{
11772 if( use_tiles ) {
11774 }
11775}
@ ACTION_DISPLAY_RADIATION
Toggle radiation map.
Definition: action.h:317

References ACTION_DISPLAY_RADIATION, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_scent()

void game::display_scent ( )
private

Definition at line 11649 of file game.cpp.

11650{
11651 if( use_tiles ) {
11653 } else {
11654 int div;
11655 bool got_value = query_int( div, _( "Set the Scent Map sensitivity to (0 to cancel)?" ) );
11656 if( !got_value || div < 1 ) {
11657 add_msg( _( "Never mind." ) );
11658 return;
11659 }
11660 shared_ptr_fast<game::draw_callback_t> scent_cb = make_shared_fast<game::draw_callback_t>( [&]() {
11661 scent.draw( w_terrain, div * 2, u.pos() + u.view_offset );
11662 } );
11663 g->add_draw_callback( scent_cb );
11664
11667 }
11668}
@ ACTION_DISPLAY_SCENT
Toggle scent map.
Definition: action.h:277
void wait_for_any_key()
Wait until the user presses a key.
Definition: input.cpp:1309
tripoint view_offset
Definition: player.h:680
void draw(const catacurses::window &win, int div, const tripoint &center) const
Definition: scent_map.cpp:70
input_manager inp_mngr
Definition: input.cpp:109
bool query_int(int &result, int default_val, const std::string &text)
Definition: output.cpp:718

References _, ACTION_DISPLAY_SCENT, add_msg(), display_toggle_overlay(), scent_map::draw(), g, inp_mngr, Character::pos(), query_int(), ui_manager::redraw(), scent, u, use_tiles, player::view_offset, w_terrain, and input_manager::wait_for_any_key().

Referenced by handle_action(), and look_around().

◆ display_temperature()

void game::display_temperature ( )
private

Definition at line 11670 of file game.cpp.

11671{
11672 if( use_tiles ) {
11674 }
11675}
@ ACTION_DISPLAY_TEMPERATURE
Toggle temperature map.
Definition: action.h:309

References ACTION_DISPLAY_TEMPERATURE, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_toggle_overlay()

void game::display_toggle_overlay ( action_id  action)

Definition at line 11640 of file game.cpp.

11641{
11642 if( display_overlay_state( action ) ) {
11643 displaying_overlays.reset();
11644 } else {
11646 }
11647}
bool display_overlay_state(action_id)
Definition: game.cpp:11635

References action, display_overlay_state(), and displaying_overlays.

Referenced by display_lighting(), display_radiation(), display_scent(), display_temperature(), display_transparency(), display_vehicle_ai(), and display_visibility().

◆ display_transparency()

void game::display_transparency ( )
private

Definition at line 11777 of file game.cpp.

11778{
11779 if( use_tiles ) {
11781 }
11782}
@ ACTION_DISPLAY_TRANSPARENCY
Toggle transparency map.
Definition: action.h:319

References ACTION_DISPLAY_TRANSPARENCY, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_vehicle_ai()

void game::display_vehicle_ai ( )
private

Definition at line 11677 of file game.cpp.

11678{
11679 if( use_tiles ) {
11681 }
11682}
@ ACTION_DISPLAY_VEHICLE_AI
Toggle vehicle autopilot data.
Definition: action.h:311

References ACTION_DISPLAY_VEHICLE_AI, display_toggle_overlay(), and use_tiles.

Referenced by handle_action().

◆ display_visibility()

void game::display_visibility ( )
private

Definition at line 11684 of file game.cpp.

11685{
11686 if( use_tiles ) {
11689 std::vector< tripoint > locations;
11690 uilist creature_menu;
11691 int num_creatures = 0;
11692 creature_menu.addentry( num_creatures++, true, MENU_AUTOASSIGN, "%s", _( "You" ) );
11693 locations.emplace_back( g->u.pos() ); // add player first.
11694 for( const Creature &critter : g->all_creatures() ) {
11695 if( critter.is_player() ) {
11696 continue;
11697 }
11698 creature_menu.addentry( num_creatures++, true, MENU_AUTOASSIGN, critter.disp_name() );
11699 locations.emplace_back( critter.pos() );
11700 }
11701
11702 pointmenu_cb callback( locations );
11703 creature_menu.callback = &callback;
11704 creature_menu.w_y_setup = 0;
11705 creature_menu.query();
11706 if( creature_menu.ret >= 0 && static_cast<size_t>( creature_menu.ret ) < locations.size() ) {
11707 Creature *creature = critter_at<Creature>( locations[creature_menu.ret] );
11709 }
11710 } else {
11712 }
11713 }
11714}
@ ACTION_DISPLAY_VISIBILITY
Toggle visibility map.
Definition: action.h:313
size_t num_creatures() const
Returns the approximate number of creatures in the reality bubble.
Definition: game.cpp:5012
Creature * displaying_visibility_creature
Creature for which to display the visibility map.
Definition: game.h:1058
Callback for uilist that pairs menu entries with points When an entry is selected,...
Definition: ui.h:423
uilist_callback * callback
Definition: ui.h:335
generic_factory< overmap_location > locations("overmap location")

References _, ACTION_DISPLAY_VISIBILITY, uilist::addentry(), uilist::callback, creature, display_overlay_state(), display_toggle_overlay(), displaying_visibility_creature, g, anonymous_namespace{overmap_location.cpp}::locations, MENU_AUTOASSIGN, num_creatures(), uilist::query(), uilist::ret, use_tiles, and uilist::w_y_setup.

Referenced by handle_action().

◆ do_turn()

bool game::do_turn ( )

MAIN GAME LOOP.

Returns true if game is over (death, saved, quit, etc.).

Definition at line 1433 of file game.cpp.

1434{
1435 if( is_game_over() ) {
1436 return cleanup_at_end();
1437 }
1438 // Actual stuff
1439 if( new_game ) {
1440 new_game = false;
1441 } else {
1442 gamemode->per_turn();
1443 calendar::turn += 1_turns;
1444 }
1445
1446 // starting a new turn, clear out temperature cache
1448 weather.clear_temp_cache();
1449
1450 if( npcs_dirty ) {
1451 load_npcs();
1452 }
1453
1456 // If controlling a vehicle that is owned by someone else
1458 vehicle *veh = veh_pointer_or_null( m.veh_at( u.pos() ) );
1459 if( veh && !veh->handle_potential_theft( dynamic_cast<player &>( u ), true ) ) {
1460 veh->handle_potential_theft( dynamic_cast<player &>( u ), false, false );
1461 }
1462 }
1463 // If riding a horse - chance to spook
1464 if( u.is_mounted() ) {
1466 }
1467 if( calendar::once_every( 1_days ) ) {
1469 }
1470
1471 // Move hordes every 2.5 min
1474 // Hordes that reached the reality bubble need to spawn,
1475 // make them spawn in invisible areas only.
1476 m.spawn_monsters( false );
1477 }
1478
1480
1481 u.update_body();
1482
1483 // Auto-save if autosave is enabled
1484 if( get_option<bool>( "AUTOSAVE" ) &&
1485 calendar::once_every( 1_turns * get_option<int>( "AUTOSAVE_TURNS" ) ) &&
1486 !u.is_dead_state() ) {
1487 autosave();
1488 }
1489
1490 weather.update_weather();
1492
1496 // Process NPC sound events before they move or they hear themselves talking
1497 for( npc &guy : all_npcs() ) {
1498 if( rl_dist( guy.pos(), u.pos() ) < MAX_VIEW_DISTANCE ) {
1500 }
1501 }
1502
1503 // Process sound events into sound markers for display to the player.
1505
1506 if( u.is_deaf() ) {
1508 }
1509
1510 if( !u.has_effect( effect_sleep ) || uquit == QUIT_WATCH ) {
1511 if( u.moves > 0 || uquit == QUIT_WATCH ) {
1512 while( u.moves > 0 || uquit == QUIT_WATCH ) {
1513 cleanup_dead();
1515 // Process any new sounds the player caused during their turn.
1516 for( npc &guy : all_npcs() ) {
1517 if( rl_dist( guy.pos(), u.pos() ) < MAX_VIEW_DISTANCE ) {
1519 }
1520 }
1523 wait_popup.reset();
1525 }
1526
1527 if( queue_screenshot ) {
1531 queue_screenshot = false;
1532 }
1533
1534 if( handle_action() ) {
1536 u.action_taken();
1537 }
1538
1539 if( is_game_over() ) {
1540 return cleanup_at_end();
1541 }
1542
1543 if( uquit == QUIT_WATCH ) {
1544 break;
1545 }
1546 if( u.activity ) {
1548 }
1549 }
1550 // Reset displayed sound markers now that the turn is over.
1551 // We only want this to happen if the player had a chance to examine the sounds.
1553 }
1554 }
1555
1556 if( driving_view_offset.x != 0 || driving_view_offset.y != 0 ) {
1557 // Still have a view offset, but might not be driving anymore,
1558 // or the option has been deactivated,
1559 // might also happen when someone dives from a moving car.
1560 // or when using the handbrake.
1561 vehicle *veh = veh_pointer_or_null( m.veh_at( u.pos() ) );
1562 calc_driving_offset( veh );
1563 }
1564
1565 // No-scent debug mutation has to be processed here or else it takes time to start working
1566 if( !u.has_active_bionic( bionic_id( "bio_scent_mask" ) ) &&
1567 !u.has_trait( trait_id( "DEBUG_NOSCENT" ) ) ) {
1570 }
1571 scent.update( u.pos(), m );
1572
1573 // We need floor cache before checking falling 'n stuff
1575
1578 m.vehmove();
1579 m.process_fields();
1580 m.process_items();
1583
1584 // Apply sounds from previous turn to monster and NPC AI.
1586 // Update vision caches for monsters. If this turns out to be expensive,
1587 // consider a stripped down cache just for monsters.
1588 m.build_map_cache( get_levz(), true );
1589 monmove();
1590 if( calendar::once_every( 5_minutes ) ) {
1592 }
1593 if( calendar::once_every( 10_seconds ) ) {
1594 for( const tripoint &elem : m.get_furn_field_locations() ) {
1595 const auto &furn = m.furn( elem ).obj();
1596 for( const emit_id &e : furn.emissions ) {
1597 g->m.emit_field( elem, e );
1598 }
1599 }
1600 }
1603 u.process_turn();
1604
1606 cleanup_dead();
1607
1608 if( u.moves < 0 && get_option<bool>( "FORCE_REDRAW" ) ) {
1611 }
1612
1613 if( get_levz() >= 0 && !u.is_underwater() ) {
1614 handle_weather_effects( weather.weather_id );
1615 }
1616
1617 const bool player_is_sleeping = u.has_effect( effect_sleep );
1618 bool wait_redraw = false;
1619 std::string wait_message;
1620 time_duration wait_refresh_rate;
1621 if( player_is_sleeping ) {
1622 wait_redraw = true;
1623 wait_message = _( "Wait till you wake up…" );
1624 wait_refresh_rate = 30_minutes;
1625 if( calendar::once_every( 1_hours ) ) {
1627 }
1628 } else if( u.has_destination() ) {
1629 wait_redraw = true;
1630 wait_message = _( "Travelling…" );
1631 wait_refresh_rate = 15_turns;
1632 } else if( const cata::optional<std::string> progress = u.activity.get_progress_message( u ) ) {
1633 wait_redraw = true;
1634 wait_message = *progress;
1635 if( u.activity.id() == ACT_AUTODRIVE ) {
1636 wait_refresh_rate = 1_turns;
1637 } else {
1638 wait_refresh_rate = 5_minutes;
1639 }
1640 }
1641 if( wait_redraw ) {
1643 calendar::once_every( std::min( 1_minutes, wait_refresh_rate ) ) ) {
1644 if( first_redraw_since_waiting_started || calendar::once_every( wait_refresh_rate ) ) {
1646 }
1647
1648 // Avoid redrawing the main UI every time due to invalidation
1650 wait_popup = std::make_unique<static_popup>();
1651 wait_popup->on_top( true ).wait_message( "%s", wait_message );
1655 }
1656 } else {
1657 // Nothing to wait for now
1658 wait_popup.reset();
1660 }
1661
1663 u.update_body_wetness( get_weather().get_precise() );
1664 u.apply_wetness_morale( weather.temperature );
1665
1666 if( calendar::once_every( 1_minutes ) ) {
1667 u.update_morale();
1668 }
1669
1670 if( calendar::once_every( 9_turns ) ) {
1672 }
1673
1674 if( !u.is_deaf() ) {
1676 }
1681
1682 // reset player noise
1683 u.volume = 0;
1684
1685 return false;
1686}
void update_morale()
Ticks down morale counters and removes them.
Definition: character.cpp:8832
void action_taken()
Called after every action, invalidates player caches.
Definition: character.cpp:863
bool check_mount_is_spooked()
Definition: character.cpp:1087
void update_bodytemp(const map &m, const weather_manager &weather)
Maintains body temperature.
Definition: character.cpp:5056
bool is_mounted() const
Definition: character.cpp:1128
bool has_destination() const
scenttype_id get_type_of_scent() const
Definition: character.cpp:8593
bool check_and_recover_morale()
Checks permanent morale for consistency and recovers it when an inconsistency is found.
Definition: character.cpp:8959
bool is_deaf() const
Definition: character.cpp:4360
void update_body()
Updates all "biology" by one turn.
Definition: character.cpp:4538
bool has_active_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id and it is powered on.
Definition: character.cpp:1871
void apply_wetness_morale(int temperature)
Recalculates morale penalty/bonus from wetness based on mutations, equipment and temperature.
Definition: suffer.cpp:1805
virtual bool is_underwater() const
Definition: creature.cpp:174
int get_levz() const
Definition: game.cpp:12401
void overmap_npc_move()
Definition: game.cpp:4521
class game::debug_hour_timer debug_hour_timer
npc_range all_npcs()
Same as all_creatures but iterators only over npcs.
Definition: game.cpp:12511
void monmove()
Definition: game.cpp:4396
void autopilot_vehicles()
process vehicles that are following the player
Definition: game.cpp:1750
void add_artifact_dreams()
Definition: game.cpp:12345
int moves_since_last_save
Definition: game.h:1088
bool take_screenshot() const
Saves a screenshot of the current viewport, as a PNG file.
Definition: game.cpp:7403
void calc_driving_offset(vehicle *veh=nullptr)
Definition: game.cpp:1331
bool cleanup_at_end()
Definition: game.cpp:1027
std::unique_ptr< static_popup > wait_popup
Definition: game.h:1124
bool queue_screenshot
Definition: game.h:1067
friend weather_manager & get_weather()
Definition: weather.cpp:64
void autosave()
Definition: game.cpp:11835
void process_activity()
Definition: game.cpp:1739
void update_stair_monsters()
Definition: game.cpp:11323
void process_voluntary_act_interrupt()
Definition: game.cpp:1700
void load_npcs()
Makes any nearby NPCs on the overmap active.
Definition: game.cpp:895
bool npcs_dirty
Has a NPC been spawned since last load?
Definition: game.h:1095
void cleanup_dead()
Definition: game.cpp:4361
bool is_game_over()
Definition: game.cpp:2675
void perhaps_add_random_npc()
Definition: game.cpp:11570
void mon_info_update()
Definition: game.cpp:4166
bool handle_action()
const T & obj() const
Definition: ammo_effect.cpp:26
void build_floor_caches()
Definition: map.cpp:7874
void process_falling()
Invoked drop_everything on cached dirty tiles.
Definition: map.cpp:2285
const std::vector< tripoint > & get_furn_field_locations() const
Definition: map.cpp:7572
void spawn_monsters(bool ignore_sight)
Spawn monsters from submap spawn points and from the overmap.
Definition: map.cpp:7531
void vehmove()
Definition: map.cpp:398
void creature_in_field(Creature &critter)
Apply field effects to the creature when it's on a square with fields.
Definition: map_field.cpp:1559
void process_fields()
Definition: map_field.cpp:141
furn_id furn(const tripoint &p) const
Definition: map.cpp:1359
void build_map_cache(int zlev, bool skip_lightmap=false)
Definition: map.cpp:8002
void process_items()
Definition: map.cpp:4592
static void process_all()
Handles mission deadline processing.
Definition: mission.cpp:98
void set_scent(const tripoint_abs_omt &loc, int strength)
Method to set a scent trace.
void process_mongroups()
Process nearby monstergroups (dying mostly).
void move_hordes()
Let hordes move a step.
const activity_id & id() const
cata::optional< std::string > get_progress_message(const avatar &u) const
Helper that returns an activity specific progress message.
bool is_dead_state() const override
Returns true if the player should be dead.
Definition: player.cpp:924
int volume
Definition: player.h:683
int scent
Definition: player.h:693
void update_body_wetness(const w_point &weather)
Maintains body wetness and handles the rate at which the player dries.
Definition: player.cpp:1711
void process_turn() override
Resets movement points and applies other non-idempotent changes.
Definition: player.cpp:319
void set(const tripoint &p, int value, const scenttype_id &type=scenttype_id())
Get the scent value at the given position.
Definition: scent_map.cpp:102
void update(const tripoint &center, map &m)
Definition: scent_map.cpp:151
static constexpr time_duration from_minutes(const T m)
Definition: calendar.h:212
void process()
Process all queued events, potentially altering the game state and modifying the event queue.
static const activity_id ACT_AUTODRIVE("ACT_AUTODRIVE")
static const efftype_id effect_sleep("sleep")
@ QUIT_WATCH
Definition: game.h:73
static constexpr int MAX_VIEW_DISTANCE
void handle_weather_effects(const weather_type_id &w)
Definition: weather.cpp:522
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490
explosion_queue & get_explosion_queue()
Definition: explosion.cpp:1155
void do_vehicle_engine_sfx()
Definition: sounds.cpp:1605
void do_hearing_loss(int turns=-1)
Definition: sounds.cpp:1600
void do_danger_music()
Definition: sounds.cpp:1604
void do_vehicle_exterior_engine_sfx()
Definition: sounds.cpp:1606
void do_fatigue()
Definition: sounds.cpp:1625
void remove_hearing_loss()
Definition: sounds.cpp:1601
void process_sound_markers(player *p)
Definition: sounds.cpp:386
void process_sounds()
Definition: sounds.cpp:304
void reset_markers()
Definition: sounds.cpp:572
vehicle * veh_pointer_or_null(const optional_vpart_position &p)

References _, ACT_AUTODRIVE, Character::action_taken(), Character::activity, add_artifact_dreams(), all_npcs(), Character::apply_wetness_morale(), autopilot_vehicles(), autosave(), map::build_floor_caches(), map::build_map_cache(), calc_driving_offset(), Character::check_and_recover_morale(), Character::check_mount_is_spooked(), cleanup_at_end(), cleanup_dead(), Character::controlling_vehicle, map::creature_in_field(), sfx::do_danger_music(), sfx::do_fatigue(), sfx::do_hearing_loss(), sfx::do_vehicle_engine_sfx(), sfx::do_vehicle_exterior_engine_sfx(), driving_view_offset, effect_sleep, explosion_handler::explosion_queue::execute(), first_redraw_since_waiting_started, time_duration::from_minutes(), map::furn(), g, gamemode, explosion_handler::get_explosion_queue(), map::get_furn_field_locations(), get_levz(), player_activity::get_progress_message(), Character::get_type_of_scent(), get_weather, Character::global_omt_location(), grid_tracker_ptr, handle_action(), vehicle::handle_potential_theft(), handle_weather_effects(), Character::has_active_bionic(), Character::has_destination(), Character::has_distant_destination(), Creature::has_effect(), Character::has_trait(), player_activity::id(), Character::in_vehicle, invalidate_main_ui_adaptor(), player::is_dead_state(), Character::is_deaf(), is_game_over(), Character::is_mounted(), Creature::is_underwater(), load_npcs(), m, MAX_VIEW_DISTANCE, mon_info_update(), monmove(), overmapbuffer::move_hordes(), Creature::moves, moves_since_last_save, new_game, npcs_dirty, int_id< T >::obj(), calendar::once_every(), overmap_buffer, overmap_npc_move(), perhaps_add_random_npc(), Character::pos(), game::debug_hour_timer::print_time(), timed_event_manager::process(), process_activity(), mission::process_all(), map::process_falling(), map::process_fields(), map::process_items(), overmapbuffer::process_mongroups(), sounds::process_sound_markers(), sounds::process_sounds(), player::process_turn(), process_voluntary_act_interrupt(), queue_screenshot, QUIT_WATCH, ui_manager::redraw(), refresh_display(), sfx::remove_hearing_loss(), reset_light_level(), sounds::reset_markers(), rl_dist(), scent, player::scent, scent_map::set(), overmapbuffer::set_scent(), map::spawn_monsters(), take_screenshot(), timed_events, calendar::turn, u, scent_map::update(), Character::update_body(), player::update_body_wetness(), Character::update_bodytemp(), Character::update_morale(), update_stair_monsters(), uquit, map::veh_at(), veh_pointer_or_null(), map::vehmove(), player::volume, wait_popup, point::x, and point::y.

◆ draw()

void game::draw ( )

Definition at line 3447 of file game.cpp.

3448{
3449 if( test_mode ) {
3450 return;
3451 }
3452
3453 //temporary fix for updating visibility for minimap
3454 ter_view_p.z = ( u.pos() + u.view_offset ).z;
3457
3458 werase( w_terrain );
3459 draw_ter();
3460 for( auto it = draw_callbacks.begin(); it != draw_callbacks.end(); ) {
3461 shared_ptr_fast<draw_callback_t> cb = it->lock();
3462 if( cb ) {
3463 ( *cb )();
3464 ++it;
3465 } else {
3466 it = draw_callbacks.erase( it );
3467 }
3468 }
3470
3471 draw_panels( true );
3472}
bool test_mode
Set to true when running in test mode (e.g.
tripoint ter_view_p
Definition: game.h:1034
void draw_panels(bool force_draw=false)
Definition: game.cpp:3474
void draw_ter(bool draw_sounds=true)
Definition: game.cpp:3588
void update_visibility_cache(int zlev)
Definition: map.cpp:5588
int z
Definition: point.h:152

References map::build_map_cache(), draw_callbacks, draw_panels(), draw_ter(), m, Character::pos(), ter_view_p, test_mode, u, map::update_visibility_cache(), player::view_offset, w_terrain, catacurses::werase(), catacurses::wnoutrefresh(), and tripoint::z.

◆ draw_below_override()

void game::draw_below_override ( const tripoint p,
bool  draw 
)

Definition at line 955 of file animation.cpp.

956{
957}

◆ draw_bullet()

void game::draw_bullet ( const tripoint t,
int  i,
const std::vector< tripoint > &  trajectory,
char  bullet 
)

Definition at line 510 of file animation.cpp.

512{
513 draw_bullet_curses( m, t, bullet, &trajectory[i] );
514}
void draw_bullet_curses(map &m, const tripoint &t, const char bullet, const tripoint *const p)
Definition: animation.cpp:451
std::vector< tripoint > trajectory
Definition: ranged.h:32

References anonymous_namespace{animation.cpp}::draw_bullet_curses(), and m.

◆ draw_critter()

void game::draw_critter ( const Creature critter,
const tripoint center 
)

Definition at line 3570 of file game.cpp.

3571{
3572 draw_critter_internal( w_terrain, critter, center, false, m, u );
3573}
static void draw_critter_internal(const catacurses::window &w, const Creature &critter, const tripoint &center, bool inverted, const map &m, const avatar &u)
Definition: game.cpp:3537

References center, draw_critter_internal(), m, u, and w_terrain.

Referenced by draw_ter().

◆ draw_critter_highlighted()

void game::draw_critter_highlighted ( const Creature critter,
const tripoint center 
)

Definition at line 3575 of file game.cpp.

3576{
3577 draw_critter_internal( w_terrain, critter, center, true, m, u );
3578}

References center, draw_critter_internal(), m, u, and w_terrain.

◆ draw_cursor()

void game::draw_cursor ( const tripoint p)

Definition at line 716 of file animation.cpp.

717{
718 const tripoint rp = relative_view_pos( *this, p );
719 mvwputch_inv( w_terrain, rp.xy(), c_light_green, 'X' );
720}
#define c_light_green
Definition: color.h:28
tripoint relative_view_pos(const game &g, const tripoint &p) noexcept
Definition: animation.cpp:119
void mvwputch_inv(const catacurses::window &w, const point &p, nc_color FG, int ch)
Definition: output.cpp:491

References c_light_green, mvwputch_inv(), anonymous_namespace{animation.cpp}::relative_view_pos(), w_terrain, and tripoint::xy().

Referenced by draw_look_around_cursor().

◆ draw_field_override()

void game::draw_field_override ( const tripoint p,
const field_type_id id 
)

Definition at line 911 of file animation.cpp.

912{
913}

◆ draw_furniture_override()

void game::draw_furniture_override ( const tripoint p,
const furn_id id 
)

Definition at line 872 of file animation.cpp.

873{
874}

◆ draw_graffiti_override()

void game::draw_graffiti_override ( const tripoint p,
bool  has 
)

Definition at line 885 of file animation.cpp.

886{
887}

◆ draw_highlight()

void game::draw_highlight ( const tripoint p)

Definition at line 729 of file animation.cpp.

730{
731 // Do nothing
732}

◆ draw_hit_mon()

void game::draw_hit_mon ( const tripoint p,
const monster m,
bool  dead = false 
)

Definition at line 573 of file animation.cpp.

574{
575 draw_hit_mon_curses( p, m, u, dead );
576}
void draw_hit_mon_curses(const tripoint &center, const monster &m, const player &u, const bool dead)
Definition: animation.cpp:544

References dead, anonymous_namespace{animation.cpp}::draw_hit_mon_curses(), m, and u.

◆ draw_hit_player()

void game::draw_hit_player ( const Character p,
int  dam 
)

Definition at line 618 of file animation.cpp.

619{
620 draw_hit_player_curses( *this, p, dam );
621}
void draw_hit_player_curses(const game &g, const Character &p, const int dam)
Definition: animation.cpp:581

References anonymous_namespace{animation.cpp}::draw_hit_player_curses().

◆ draw_item_override()

void game::draw_item_override ( const tripoint p,
const itype_id id,
const mtype_id mid,
bool  hilite 
)

Definition at line 925 of file animation.cpp.

927{
928}

◆ draw_line() [1/2]

void game::draw_line ( const tripoint p,
const std::vector< tripoint > &  points 
)

Definition at line 702 of file animation.cpp.

703{
704 draw_line_curses( *this, points );
705}
void draw_line_curses(game &g, const std::vector< tripoint > &points)
Definition: animation.cpp:682

References anonymous_namespace{animation.cpp}::draw_line_curses().

◆ draw_line() [2/2]

void game::draw_line ( const tripoint p,
const tripoint center_point,
const std::vector< tripoint > &  points,
bool  noreveal = false 
)

Definition at line 669 of file animation.cpp.

671{
672 if( !u.sees( p ) ) {
673 return;
674 }
675
676 draw_line_curses( *this, center, points, noreveal );
677}

References center, anonymous_namespace{animation.cpp}::draw_line_curses(), Character::sees(), and u.

Referenced by draw_ter().

◆ draw_look_around_cursor()

void game::draw_look_around_cursor ( const tripoint lp,
const visibility_variables cache 
)

Definition at line 5948 of file game.cpp.

5949{
5950 if( !liveview.is_enabled() ) {
5951#if defined( TILES )
5952 if( is_draw_tiles_mode() ) {
5953 draw_cursor( lp );
5954 return;
5955 }
5956#endif
5957 const tripoint view_center = u.pos() + u.view_offset;
5958 visibility_type visibility = VIS_HIDDEN;
5959 const bool inbounds = m.inbounds( lp );
5960 if( inbounds ) {
5961 visibility = m.get_visibility( m.apparent_light_at( lp, cache ), cache );
5962 }
5963 if( visibility == VIS_CLEAR ) {
5964 const Creature *const creature = critter_at( lp, true );
5965 if( creature != nullptr && u.sees( *creature ) ) {
5966 creature->draw( w_terrain, view_center, true );
5967 } else {
5968 m.drawsq( w_terrain, lp, drawsq_params().highlight( true ).center( view_center ) );
5969 }
5970 } else {
5971 std::string visibility_indicator;
5972 nc_color visibility_indicator_color = c_white;
5973 switch( visibility ) {
5974 case VIS_CLEAR:
5975 // Already handled by the outer if statement
5976 break;
5977 case VIS_BOOMER:
5978 case VIS_BOOMER_DARK:
5979 visibility_indicator = '#';
5980 visibility_indicator_color = c_pink;
5981 break;
5982 case VIS_DARK:
5983 visibility_indicator = '#';
5984 visibility_indicator_color = c_dark_gray;
5985 break;
5986 case VIS_LIT:
5987 visibility_indicator = '#';
5988 visibility_indicator_color = c_light_gray;
5989 break;
5990 case VIS_HIDDEN:
5991 visibility_indicator = 'x';
5992 visibility_indicator_color = c_white;
5993 break;
5994 }
5995
5996 const tripoint screen_pos = point( POSX, POSY ) + lp - view_center;
5997 mvwputch( w_terrain, screen_pos.xy(), visibility_indicator_color, visibility_indicator );
5998 }
5999 }
6000}
void draw_cursor(const tripoint &p)
Definition: animation.cpp:716
T * critter_at(const tripoint &p, bool allow_hallucination=false)
Returns the Creature at the given location.
Definition: game.cpp:4832
bool is_enabled()
Definition: live_view.cpp:75
virtual bool inbounds(const tripoint &p) const
Definition: map.cpp:7582
visibility_type get_visibility(lit_level ll, const visibility_variables &cache) const
Definition: map.cpp:5634
lit_level apparent_light_at(const tripoint &p, const visibility_variables &cache) const
Determine the visible light level for a tile, based on light_at for the tile, vision distance,...
Definition: lightmap.cpp:698
void drawsq(const catacurses::window &w, const tripoint &p, const drawsq_params &params) const
Draw the map tile at the given coordinate.
Definition: map.cpp:5812
#define c_dark_gray
Definition: color.h:20
#define c_pink
Definition: color.h:31
visibility_type
Definition: enums.h:57
@ VIS_CLEAR
Definition: enums.h:59
@ VIS_BOOMER
Definition: enums.h:61
@ VIS_DARK
Definition: enums.h:62
@ VIS_BOOMER_DARK
Definition: enums.h:63
@ VIS_HIDDEN
Definition: enums.h:58
@ VIS_LIT
Definition: enums.h:60
bool is_draw_tiles_mode()
Check whether we're in tile drawing mode.
Definition: output.cpp:2029
Draw parameters used by map::drawsq() and similar methods.
Definition: map.h:176

References map::apparent_light_at(), c_dark_gray, c_light_gray, c_pink, c_white, center, creature, critter_at(), draw_cursor(), map::drawsq(), map::get_visibility(), map::inbounds(), is_draw_tiles_mode(), live_view::is_enabled(), liveview, m, mvwputch(), Character::pos(), POSX, POSY, Character::sees(), u, player::view_offset, VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, VIS_LIT, w_terrain, and tripoint::xy().

Referenced by look_around().

◆ draw_minimap()

void game::draw_minimap ( )
private

Definition at line 3648 of file game.cpp.

3649{
3650
3651 // Draw the box
3652 werase( w_minimap );
3654
3655 const tripoint_abs_omt curs = u.global_omt_location();
3656 const point_abs_omt curs2( curs.xy() );
3658 bool drew_mission = targ == overmap::invalid_tripoint;
3659
3660 for( int i = -2; i <= 2; i++ ) {
3661 for( int j = -2; j <= 2; j++ ) {
3662 const point_abs_omt om( curs2 + point( i, j ) );
3663 nc_color ter_color;
3664 tripoint_abs_omt omp( om, get_levz() );
3665 std::string ter_sym;
3666 const bool seen = overmap_buffer.seen( omp );
3667 const bool vehicle_here = overmap_buffer.has_vehicle( omp );
3668 if( overmap_buffer.has_note( omp ) ) {
3669
3670 const std::string &note_text = overmap_buffer.note( omp );
3671
3672 ter_color = c_yellow;
3673 ter_sym = "N";
3674
3675 int symbolIndex = note_text.find( ':' );
3676 int colorIndex = note_text.find( ';' );
3677
3678 bool symbolFirst = symbolIndex < colorIndex;
3679
3680 if( colorIndex > -1 && symbolIndex > -1 ) {
3681 if( symbolFirst ) {
3682 if( colorIndex > 4 ) {
3683 colorIndex = -1;
3684 }
3685 if( symbolIndex > 1 ) {
3686 symbolIndex = -1;
3687 colorIndex = -1;
3688 }
3689 } else {
3690 if( symbolIndex > 4 ) {
3691 symbolIndex = -1;
3692 }
3693 if( colorIndex > 2 ) {
3694 colorIndex = -1;
3695 }
3696 }
3697 } else if( colorIndex > 2 ) {
3698 colorIndex = -1;
3699 } else if( symbolIndex > 1 ) {
3700 symbolIndex = -1;
3701 }
3702
3703 if( symbolIndex > -1 ) {
3704 int symbolStart = 0;
3705 if( colorIndex > -1 && !symbolFirst ) {
3706 symbolStart = colorIndex + 1;
3707 }
3708 ter_sym = note_text.substr( symbolStart, symbolIndex - symbolStart ).c_str()[0];
3709 }
3710
3711 if( colorIndex > -1 ) {
3712
3713 int colorStart = 0;
3714
3715 if( symbolIndex > -1 && symbolFirst ) {
3716 colorStart = symbolIndex + 1;
3717 }
3718
3719 std::string sym = note_text.substr( colorStart, colorIndex - colorStart );
3720
3721 if( sym.length() == 2 ) {
3722 if( sym == "br" ) {
3723 ter_color = c_brown;
3724 } else if( sym == "lg" ) {
3725 ter_color = c_light_gray;
3726 } else if( sym == "dg" ) {
3727 ter_color = c_dark_gray;
3728 }
3729 } else {
3730 char colorID = sym.c_str()[0];
3731 if( colorID == 'r' ) {
3732 ter_color = c_light_red;
3733 } else if( colorID == 'R' ) {
3734 ter_color = c_red;
3735 } else if( colorID == 'g' ) {
3736 ter_color = c_light_green;
3737 } else if( colorID == 'G' ) {
3738 ter_color = c_green;
3739 } else if( colorID == 'b' ) {
3740 ter_color = c_light_blue;
3741 } else if( colorID == 'B' ) {
3742 ter_color = c_blue;
3743 } else if( colorID == 'W' ) {
3744 ter_color = c_white;
3745 } else if( colorID == 'C' ) {
3746 ter_color = c_cyan;
3747 } else if( colorID == 'c' ) {
3748 ter_color = c_light_cyan;
3749 } else if( colorID == 'P' ) {
3750 ter_color = c_pink;
3751 } else if( colorID == 'm' ) {
3752 ter_color = c_magenta;
3753 }
3754 }
3755 }
3756 } else if( !seen ) {
3757 ter_sym = " ";
3758 ter_color = c_black;
3759 } else if( vehicle_here ) {
3760 ter_color = c_cyan;
3761 ter_sym = "c";
3762 } else {
3763 const oter_id &cur_ter = overmap_buffer.ter( omp );
3764 ter_sym = cur_ter->get_symbol();
3765 if( overmap_buffer.is_explored( omp ) ) {
3766 ter_color = c_dark_gray;
3767 } else {
3768 ter_color = cur_ter->get_color();
3769 }
3770 }
3771 if( !drew_mission && targ.xy() == omp.xy() ) {
3772 // If there is a mission target, and it's not on the same
3773 // overmap terrain as the player character, mark it.
3774 // TODO: Inform player if the mission is above or below
3775 drew_mission = true;
3776 if( i != 0 || j != 0 ) {
3777 ter_color = red_background( ter_color );
3778 }
3779 }
3780 if( i == 0 && j == 0 ) {
3781 mvwputch_hi( w_minimap, point( 3, 3 ), ter_color, ter_sym );
3782 } else {
3783 mvwputch( w_minimap, point( 3 + i, 3 + j ), ter_color, ter_sym );
3784 }
3785 }
3786 }
3787
3788 // Print arrow to mission if we have one!
3789 if( !drew_mission ) {
3790 double slope = curs2.x() != targ.x() ?
3791 static_cast<double>( targ.y() - curs2.y() ) / ( targ.x() - curs2.x() ) : 4;
3792
3793 if( curs2.x() == targ.x() || std::fabs( slope ) > 3.5 ) { // Vertical slope
3794 if( targ.y() > curs2.y() ) {
3795 mvwputch( w_minimap, point( 3, 6 ), c_red, "*" );
3796 } else {
3797 mvwputch( w_minimap, point( 3, 0 ), c_red, "*" );
3798 }
3799 } else {
3800 int arrowx = -1;
3801 int arrowy = -1;
3802 if( std::fabs( slope ) >= 1. ) { // y diff is bigger!
3803 arrowy = targ.y() > curs2.y() ? 6 : 0;
3804 arrowx =
3805 static_cast<int>( 3 + 3 * ( targ.y() > curs2.y() ? slope : ( 0 - slope ) ) );
3806 if( arrowx < 0 ) {
3807 arrowx = 0;
3808 }
3809 if( arrowx > 6 ) {
3810 arrowx = 6;
3811 }
3812 } else {
3813 arrowx = targ.x() > curs2.x() ? 6 : 0;
3814 arrowy = static_cast<int>( 3 + 3 * ( targ.x() > curs2.x() ? slope : -slope ) );
3815 if( arrowy < 0 ) {
3816 arrowy = 0;
3817 }
3818 if( arrowy > 6 ) {
3819 arrowy = 6;
3820 }
3821 }
3822 char glyph = '*';
3823 if( targ.z() > u.posz() ) {
3824 glyph = '^';
3825 } else if( targ.z() < u.posz() ) {
3826 glyph = 'v';
3827 }
3828
3829 mvwputch( w_minimap, point( arrowx, arrowy ), c_red, glyph );
3830 }
3831 }
3832
3833 const int sight_points = g->u.overmap_sight_range( g->light_level( g->u.posz() ) );
3834 for( int i = -3; i <= 3; i++ ) {
3835 for( int j = -3; j <= 3; j++ ) {
3836 if( i > -3 && i < 3 && j > -3 && j < 3 ) {
3837 continue; // only do hordes on the border, skip inner map
3838 }
3839 const tripoint_abs_omt omp( curs2 + point( i, j ), get_levz() );
3841 if( overmap_buffer.seen( omp )
3842 && g->u.overmap_los( omp, sight_points ) ) {
3843 mvwputch( w_minimap, point( i + 3, j + 3 ), c_green,
3844 overmap_buffer.get_horde_size( omp ) > HORDE_VISIBILITY_SIZE * 2 ? 'Z' : 'z' );
3845 }
3846 }
3847 }
3848 }
3849
3851}
tripoint_abs_omt get_active_mission_target() const
Returns the target of the active mission or overmap::invalid_tripoint if there is no active mission.
Definition: avatar.cpp:196
constexpr auto & x()
Definition: coordinates.h:118
constexpr auto & z()
Definition: coordinates.h:133
constexpr auto & y()
Definition: coordinates.h:124
constexpr auto xy() const
Definition: coordinates.h:130
static constexpr tripoint_abs_omt invalid_tripoint
Dummy value, used to indicate that a point returned by a function is invalid.
Definition: overmap.h:307
bool seen(const tripoint_abs_omt &p)
const std::string & note(const tripoint_abs_omt &p)
int get_horde_size(const tripoint_abs_omt &p)
bool is_explored(const tripoint_abs_omt &p)
const oter_id & ter(const tripoint_abs_omt &p)
Returns the overmap terrain at the given OMT coordinates.
bool has_note(const tripoint_abs_omt &p)
Uses global overmap terrain coordinates.
bool has_vehicle(const tripoint_abs_omt &p)
nc_color red_background(const nc_color &c)
Definition: color.cpp:515
#define c_blue
Definition: color.h:23
#define c_black
Definition: color.h:17
#define c_light_blue
Definition: color.h:29
#define c_yellow
Definition: color.h:32
#define c_light_cyan
Definition: color.h:30
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
static constexpr int HORDE_VISIBILITY_SIZE
constexpr scale om
Definition: coordinates.h:34
void mvwputch_hi(const catacurses::window &w, const point &p, nc_color FG, int ch)
Definition: output.cpp:508
std::string get_symbol(const bool from_land_use_code=false) const
Definition: omdata.h:283
nc_color get_color(const bool from_land_use_code=false) const
Definition: omdata.h:291

References c_black, c_blue, c_brown, c_cyan, c_dark_gray, c_green, c_light_blue, c_light_cyan, c_light_gray, c_light_green, c_light_red, c_magenta, c_pink, c_red, c_white, c_yellow, draw_border(), units::fabs(), g, avatar::get_active_mission_target(), oter_t::get_color(), overmapbuffer::get_horde_size(), get_levz(), oter_t::get_symbol(), Character::global_omt_location(), overmapbuffer::has_note(), overmapbuffer::has_vehicle(), HORDE_VISIBILITY_SIZE, overmap::invalid_tripoint, overmapbuffer::is_explored(), mvwputch(), mvwputch_hi(), overmapbuffer::note(), coords::om, overmap_buffer, Character::posz(), red_background(), overmapbuffer::seen(), overmapbuffer::ter(), u, w_minimap, catacurses::werase(), catacurses::wnoutrefresh(), coords::coord_point< Point, Origin, Scale >::x(), coords::coord_point< Point, Origin, Scale >::xy(), coords::coord_point< Point, Origin, Scale >::y(), and coords::coord_point< Point, Origin, Scale >::z().

◆ draw_monster_override()

void game::draw_monster_override ( const tripoint p,
const mtype_id id,
int  count,
bool  more,
Creature::Attitude  att 
)

Definition at line 969 of file animation.cpp.

971{
972}

◆ draw_panels()

void game::draw_panels ( bool  force_draw = false)

Definition at line 3474 of file game.cpp.

3475{
3476 static int previous_turn = -1;
3477 const int current_turn = to_turns<int>( calendar::turn - calendar::turn_zero );
3478 const bool draw_this_turn = current_turn > previous_turn || force_draw;
3479 auto &mgr = panel_manager::get_manager();
3480 int y = 0;
3481 const bool sidebar_right = get_option<std::string>( "SIDEBAR_POSITION" ) == "right";
3482 int spacer = get_option<bool>( "SIDEBAR_SPACERS" ) ? 1 : 0;
3483 int log_height = 0;
3484 for( const window_panel &panel : mgr.get_current_layout() ) {
3485 if( panel.get_height() != -2 && panel.toggle && panel.render() ) {
3486 log_height += panel.get_height() + spacer;
3487 }
3488 }
3489 log_height = std::max( TERMY - log_height, 3 );
3490 for( const window_panel &panel : mgr.get_current_layout() ) {
3491 if( panel.render() ) {
3492 // height clamped to window height.
3493 int h = std::min( panel.get_height(), TERMY - y );
3494 if( h == -2 ) {
3495 h = log_height;
3496 }
3497 h += spacer;
3498 if( panel.toggle && panel.render() && h > 0 ) {
3499 if( panel.always_draw || draw_this_turn ) {
3500 panel.draw( u, catacurses::newwin( h, panel.get_width(),
3501 point( sidebar_right ? TERMX - panel.get_width() : 0, y ) ) );
3502 }
3503 if( show_panel_adm ) {
3504 const std::string panel_name = _( panel.get_name() );
3505 const int panel_name_width = utf8_width( panel_name );
3506 auto label = catacurses::newwin( 1, panel_name_width, point( sidebar_right ?
3507 TERMX - panel.get_width() - panel_name_width - 1 : panel.get_width() + 1, y ) );
3508 werase( label );
3509 mvwprintz( label, point_zero, c_light_red, panel_name );
3511 label = catacurses::newwin( h, 1,
3512 point( sidebar_right ? TERMX - panel.get_width() - 1 : panel.get_width(), y ) );
3513 werase( label );
3514 if( h == 1 ) {
3516 } else {
3518 for( int i = 1; i < h - 1; i++ ) {
3520 }
3521 mvwputch( label, point( 0, h - 1 ), c_light_red, sidebar_right ? LINE_XXOO : LINE_XOOX );
3522 }
3524 }
3525 y += h;
3526 }
3527 }
3528 }
3529 previous_turn = current_turn;
3530}
bool show_panel_adm
Definition: game.h:1062
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26
#define LINE_XOXO
Definition: output.h:39
#define LINE_OXOX
Definition: output.h:40
#define LINE_OXXX
Definition: output.h:48
#define LINE_XOOX
Definition: output.h:44
#define LINE_XXOO
Definition: output.h:41
Struct used for storing labels (easier to json opposed to a std::map<point, std::string>)
Definition: vehicle.h:578

References _, c_light_red, panel_manager::get_manager(), LINE_OXOX, LINE_OXXX, LINE_XOOX, LINE_XOXO, LINE_XXOO, mvwprintz(), mvwputch(), catacurses::newwin(), point_zero, show_panel_adm, TERMX, TERMY, calendar::turn, calendar::turn_zero, u, utf8_width(), catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by draw().

◆ draw_pixel_minimap()

void game::draw_pixel_minimap ( const catacurses::window w)

Definition at line 3532 of file game.cpp.

3533{
3534 w_pixel_minimap = w;
3535}

References w_pixel_minimap.

◆ draw_radiation_override()

void game::draw_radiation_override ( const tripoint p,
int  rad 
)

Definition at line 846 of file animation.cpp.

847{
848}

◆ draw_sct()

void game::draw_sct ( )

Definition at line 797 of file animation.cpp.

798{
799 draw_sct_curses( *this );
800}
void draw_sct_curses(const game &g)
Definition: animation.cpp:764

References anonymous_namespace{animation.cpp}::draw_sct_curses().

Referenced by get_player_input().

◆ draw_ter() [1/2]

void game::draw_ter ( bool  draw_sounds = true)

Definition at line 3588 of file game.cpp.

3589{
3591 draw_sounds );
3592}
bool is_looking
Definition: game.h:250

References draw_ter(), is_looking, Character::pos(), u, and player::view_offset.

Referenced by draw(), and draw_ter().

◆ draw_ter() [2/2]

void game::draw_ter ( const tripoint center,
bool  looking = false,
bool  draw_sounds = true 
)

Definition at line 3594 of file game.cpp.

3595{
3597
3598 m.draw( w_terrain, center );
3599
3600 if( draw_sounds ) {
3602 }
3603
3604 for( Creature &critter : all_creatures() ) {
3605 draw_critter( critter, center );
3606 }
3607
3608 if( !destination_preview.empty() && u.view_offset.z == 0 ) {
3609 // Draw auto-move preview trail
3610 const tripoint &final_destination = destination_preview.back();
3611 tripoint line_center = u.pos() + u.view_offset;
3612 draw_line( final_destination, line_center, destination_preview, true );
3613 mvwputch( w_terrain, final_destination.xy() - u.view_offset.xy() + point( POSX - u.posx(),
3614 POSY - u.posy() ), c_white, 'X' );
3615 }
3616
3617 if( u.controlling_vehicle && !looking ) {
3618 draw_veh_dir_indicator( false );
3619 draw_veh_dir_indicator( true );
3620 }
3621 // Place the cursor over the player as is expected by screen readers.
3622 wmove( w_terrain, -center.xy() + g->u.pos().xy() + point( POSX, POSY ) );
3623}
int posx() const override
Definition: character.h:838
int posy() const override
Definition: character.h:841
void draw_critter(const Creature &critter, const tripoint &center)
Definition: game.cpp:3570
Creature_range all_creatures()
Returns an anonymous range that contains all creatures.
Definition: game.cpp:12501
std::vector< tripoint > destination_preview
Definition: game.h:1114
void draw_veh_dir_indicator(bool next)
Definition: game.cpp:3640
void draw_line(const tripoint &p, const tripoint &center_point, const std::vector< tripoint > &points, bool noreveal=false)
Definition: animation.cpp:669
void draw(const catacurses::window &w, const tripoint &center)
Draw a visible part of the map into w.
Definition: map.cpp:5684
static void draw_footsteps(const catacurses::window &window, const tripoint &offset)
Definition: game.cpp:3260
void wmove(const window &win, const point &p)
Definition: ncurses_def.cpp:98

References all_creatures(), c_white, center, Character::controlling_vehicle, destination_preview, map::draw(), draw_critter(), draw_footsteps(), draw_line(), draw_veh_dir_indicator(), g, m, mvwputch(), Character::pos(), Character::posx(), POSX, Character::posy(), POSY, ter_view_p, u, player::view_offset, w_terrain, catacurses::wmove(), tripoint::xy(), and tripoint::z.

◆ draw_terrain_override()

void game::draw_terrain_override ( const tripoint p,
const ter_id id 
)

Definition at line 859 of file animation.cpp.

860{
861}

◆ draw_trail_to_square()

void game::draw_trail_to_square ( const tripoint t,
bool  bDrawX 
)

Definition at line 7251 of file game.cpp.

7252{
7253 ::draw_trail( u.pos(), u.pos() + t, bDrawX );
7254}
static void draw_trail(const tripoint &start, const tripoint &end, bool bDrawX)
Definition: game.cpp:7221

References draw_trail(), Character::pos(), and u.

◆ draw_trap_override()

void game::draw_trap_override ( const tripoint p,
const trap_id id 
)

Definition at line 898 of file animation.cpp.

899{
900}

◆ draw_veh_dir_indicator()

void game::draw_veh_dir_indicator ( bool  next)

Definition at line 3640 of file game.cpp.

3641{
3642 if( const cata::optional<tripoint> indicator_offset = get_veh_dir_indicator_location( next ) ) {
3643 auto col = next ? c_white : c_dark_gray;
3644 mvwputch( w_terrain, indicator_offset->xy() - u.view_offset.xy() + point( POSX, POSY ), col, 'X' );
3645 }
3646}
cata::optional< tripoint > get_veh_dir_indicator_location(bool next) const
Returns the location where the indicator should go relative to the reality bubble,...
Definition: game.cpp:3625

References c_dark_gray, c_white, get_veh_dir_indicator_location(), mvwputch(), POSX, POSY, u, player::view_offset, w_terrain, and tripoint::xy().

Referenced by draw_ter().

◆ draw_vpart_override()

void game::draw_vpart_override ( const tripoint p,
const vpart_id id,
int  part_mod,
units::angle  veh_dir,
bool  hilite,
const point mount 
)

Definition at line 941 of file animation.cpp.

943{
944}

◆ draw_weather()

void game::draw_weather ( const weather_printable wPrint)

Definition at line 756 of file animation.cpp.

757{
759}
void draw_weather_curses(const catacurses::window &win, const weather_printable &w)
Definition: animation.cpp:737

References anonymous_namespace{animation.cpp}::draw_weather_curses(), and w_terrain.

Referenced by get_player_input().

◆ draw_zones()

void game::draw_zones ( const tripoint start,
const tripoint end,
const tripoint offset 
)

Definition at line 832 of file animation.cpp.

833{
834 draw_zones_curses( w_terrain, start, end, offset );
835}
void draw_zones_curses(const catacurses::window &w, const tripoint &start, const tripoint &end, const tripoint &offset)
Definition: animation.cpp:805

References anonymous_namespace{animation.cpp}::draw_zones_curses(), and w_terrain.

◆ drop()

void game::drop ( )
private

Definition at line 8293 of file game.cpp.

8294{
8296}
void drop(item_location loc, const tripoint &where)
Drops an item to the specified location.
Definition: character.cpp:2488
drop_locations multidrop(player &p)
Select items to drop.

References Character::drop(), game_menus::inv::multidrop(), Character::pos(), and u.

Referenced by handle_action().

◆ drop_in_direction()

void game::drop_in_direction ( )
private

Definition at line 8298 of file game.cpp.

8299{
8300 if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Drop where?" ) ) ) {
8301 u.drop( game_menus::inv::multidrop( u ), *pnt );
8302 }
8303}

References _, choose_adjacent(), Character::drop(), game_menus::inv::multidrop(), and u.

Referenced by handle_action().

◆ dump_stats()

bool game::dump_stats ( const std::string &  what,
dump_mode  mode,
const std::vector< std::string > &  opts 
)

write statistics to stdout and

Returns
true if successful

Definition at line 37 of file dump.cpp.

39{
40 try {
41 loading_ui ui( false );
43 load_packs( _( "Loading content packs" ), { mod_id( "dda" ) }, ui );
45 } catch( const std::exception &err ) {
46 std::cerr << "Error loading data from json: " << err.what() << std::endl;
47 return false;
48 }
49
50 std::vector<std::string> header;
51 std::vector<std::vector<std::string>> rows;
52
53 int scol = 0; // sorting column
54
55 std::map<std::string, standard_npc> test_npcs;
56 test_npcs[ "S1" ] = standard_npc( "S1", { 0, 0, 2 }, { "gloves_survivor", "mask_lsurvivor" },
57 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
58 test_npcs[ "S2" ] = standard_npc( "S2", { 0, 0, 3 }, { "gloves_fingerless", "sunglasses" },
59 4, 8, 8, 8, 10 /* PER 10 */ );
60 test_npcs[ "S3" ] = standard_npc( "S3", { 0, 0, 4 }, { "gloves_plate", "helmet_plate" },
61 4, 10, 8, 8, 8 /* STAT 10 */ );
62 test_npcs[ "S4" ] = standard_npc( "S4", { 0, 0, 5 }, {}, 0, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
63 test_npcs[ "S5" ] = standard_npc( "S5", { 0, 0, 6 }, {}, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
64 test_npcs[ "S6" ] = standard_npc( "S6", { 0, 0, 7 }, { "gloves_hsurvivor", "mask_hsurvivor" },
65 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
66
67 std::map<std::string, item> test_items;
68 test_items[ "G1" ] = item( "glock_19" ).ammo_set( itype_id( "9mm" ) );
69 test_items[ "G2" ] = item( "hk_mp5" ).ammo_set( itype_id( "9mm" ) );
70 test_items[ "G3" ] = item( "ar15" ).ammo_set( itype_id( "223" ) );
71 test_items[ "G4" ] = item( "remington_700" ).ammo_set( itype_id( "270" ) );
72 test_items[ "G4" ].put_in( item( "rifle_scope" ) );
73
74 if( what == "AMMO" ) {
75 header = {
76 "Name", "Ammo", "Volume", "Weight", "Stack",
77 "Range", "Dispersion", "Recoil", "Damage", "Pierce", "Damage multiplier"
78 };
79 auto dump = [&rows]( const item & obj ) {
80 std::vector<std::string> r;
81 r.push_back( obj.tname( 1, false ) );
82 r.push_back( obj.ammo_type().str() );
83 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
84 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
85 r.push_back( std::to_string( obj.type->stack_size ) );
86 r.push_back( std::to_string( obj.type->ammo->range ) );
87 r.push_back( std::to_string( obj.type->ammo->dispersion ) );
88 r.push_back( std::to_string( obj.type->ammo->recoil ) );
89 damage_instance damage = obj.type->ammo->damage;
90 r.push_back( std::to_string( damage.total_damage() ) );
91 r.push_back( std::to_string( damage.empty() ? 0 : ( *damage.begin() ).res_pen ) );
92 rows.push_back( r );
93 };
94 for( const itype *e : item_controller->all() ) {
95 if( e->ammo ) {
96 dump( item( e, calendar::turn, item::solitary_tag {} ) );
97 }
98 }
99
100 } else if( what == "ARMOR" ) {
101 header = {
102 "Name", "Encumber (fit)", "Warmth", "Weight", "Storage", "Coverage", "Bash", "Cut", "Bullet", "Acid", "Fire"
103 };
104 auto dump = [&rows]( const item & obj ) {
105 std::vector<std::string> r;
106 r.push_back( obj.tname( 1, false ) );
107 r.push_back( std::to_string( obj.get_encumber( g->u ) ) );
108 r.push_back( std::to_string( obj.get_warmth() ) );
109 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
110 r.push_back( std::to_string( obj.get_storage() / units::legacy_volume_factor ) );
111 r.push_back( std::to_string( obj.get_coverage() ) );
112 r.push_back( std::to_string( obj.bash_resist() ) );
113 r.push_back( std::to_string( obj.cut_resist() ) );
114 r.push_back( std::to_string( obj.bullet_resist() ) );
115 r.push_back( std::to_string( obj.acid_resist() ) );
116 r.push_back( std::to_string( obj.fire_resist() ) );
117 rows.push_back( r );
118 };
119
120 body_part bp = opts.empty() ? num_bp : get_body_part_token( opts.front() );
121
122 for( const itype *e : item_controller->all() ) {
123 if( e->armor ) {
124 item obj( e );
125 if( bp == num_bp || obj.covers( bp ) ) {
126 if( obj.has_flag( flag_VARSIZE ) ) {
127 obj.set_flag( "FIT" );
128 }
129 dump( obj );
130 }
131 }
132 }
133
134 } else if( what == "EDIBLE" ) {
135 header = {
136 "Name", "Volume", "Weight", "Stack", "Calories", "Quench", "Healthy"
137 };
138 for( const auto &v : vitamin::all() ) {
139 header.push_back( v.second.name() );
140 }
141 auto dump = [&rows]( const item & obj ) {
142 std::vector<std::string> r;
143 r.push_back( obj.tname( 1, false ) );
144 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
145 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
146 r.push_back( std::to_string( obj.type->stack_size ) );
147 r.push_back( std::to_string( obj.get_comestible()->default_nutrition.kcal ) );
148 r.push_back( std::to_string( obj.get_comestible()->quench ) );
149 r.push_back( std::to_string( obj.get_comestible()->healthy ) );
150 auto vits = obj.get_comestible()->default_nutrition.vitamins;
151 for( const auto &v : vitamin::all() ) {
152 r.push_back( std::to_string( vits[ v.first ] ) );
153 }
154 rows.push_back( r );
155 };
156
157 for( const itype *e : item_controller->all() ) {
159
160 if( food.is_food() && g->u.can_eat( food ).success() ) {
161 dump( food );
162 }
163 }
164
165 } else if( what == "GUN" ) {
166 header = {
167 "Name", "Ammo", "Volume", "Weight", "Capacity",
168 "Range", "Dispersion", "Effective recoil", "Damage", "Pierce",
169 "Aim time", "Effective range", "Snapshot range", "Max range"
170 };
171
172 std::set<std::string> locations;
173 for( const itype *e : item_controller->all() ) {
174 if( e->gun ) {
175 std::transform( e->gun->valid_mod_locations.begin(),
176 e->gun->valid_mod_locations.end(),
177 std::inserter( locations, locations.begin() ),
178 []( const std::pair<gunmod_location, int> &q ) {
179 return q.first.name();
180 } );
181 }
182 }
183 for( const auto &e : locations ) {
184 header.push_back( e );
185 }
186
187 auto dump = [&rows, &locations]( const standard_npc & who, const item & obj ) {
188 std::vector<std::string> r;
189 r.push_back( obj.tname( 1, false ) );
190 r.push_back( !obj.ammo_types().empty() ? enumerate_as_string( obj.ammo_types().begin(),
191 obj.ammo_types().end(), []( const ammotype & at ) {
192 return at.str();
194 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
195 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
196 r.push_back( std::to_string( obj.ammo_capacity() ) );
197 r.push_back( std::to_string( obj.gun_range() ) );
198 r.push_back( std::to_string( obj.gun_dispersion() ) );
199 r.push_back( std::to_string( obj.gun_recoil() ) );
200 damage_instance damage = obj.gun_damage();
201 r.push_back( std::to_string( damage.total_damage() ) );
202 r.push_back( std::to_string( damage.empty() ? 0 : ( *damage.begin() ).res_pen ) );
203
204 r.push_back( std::to_string( who.gun_engagement_moves( obj ) ) );
205
206 for( const auto &e : locations ) {
207 const auto &vml = obj.type->gun->valid_mod_locations;
208 const auto iter = vml.find( e );
209 r.push_back( std::to_string( iter != vml.end() ? iter->second : 0 ) );
210 }
211 rows.push_back( r );
212 };
213 for( const itype *e : item_controller->all() ) {
214 if( e->gun ) {
215 item gun( e );
216 if( !gun.magazine_integral() ) {
217 gun.put_in( item( gun.magazine_default() ) );
218 }
219 gun.ammo_set( gun.ammo_default( false ), gun.ammo_capacity() );
220
221 dump( test_npcs[ "S1" ], gun );
222
223 if( gun.type->gun->barrel_length > 0_ml ) {
224 gun.put_in( item( "barrel_small" ) );
225 dump( test_npcs[ "S1" ], gun );
226 }
227 }
228 }
229
230 } else if( what == "RECIPE" ) {
231
232 // optionally filter recipes to include only those using specified skills
233 recipe_subset dict;
234 for( const auto &r : recipe_dict ) {
235 if( opts.empty() || std::any_of( opts.begin(), opts.end(), [&r]( const std::string & s ) {
236 if( r.second.skill_used == skill_id( s ) && r.second.difficulty > 0 ) {
237 return true;
238 }
239 const auto iter = r.second.required_skills.find( skill_id( s ) );
240 return iter != r.second.required_skills.end() && iter->second > 0;
241 } ) ) {
242 dict.include( &r.second );
243 }
244 }
245
246 // only consider skills that are required by at least one recipe
247 std::vector<Skill> sk;
248 std::copy_if( Skill::skills.begin(), Skill::skills.end(),
249 std::back_inserter( sk ), [&dict]( const Skill & s ) {
250 return std::any_of( dict.begin(), dict.end(), [&s]( const recipe * r ) {
251 return r->skill_used == s.ident() ||
252 r->required_skills.find( s.ident() ) != r->required_skills.end();
253 } );
254 } );
255
256 header = { "Result" };
257
258 for( const auto &e : sk ) {
259 header.push_back( e.ident().str() );
260 }
261
262 for( const recipe *e : dict ) {
263 std::vector<std::string> r;
264 r.push_back( e->result_name() );
265 for( const auto &s : sk ) {
266 if( e->skill_used == s.ident() ) {
267 r.push_back( std::to_string( e->difficulty ) );
268 } else {
269 auto iter = e->required_skills.find( s.ident() );
270 r.push_back( std::to_string( iter != e->required_skills.end() ? iter->second : 0 ) );
271 }
272 }
273 rows.push_back( r );
274 }
275
276 } else if( what == "VEHICLE" ) {
277 header = {
278 "Name", "Weight (empty)", "Weight (fueled)",
279 "Max velocity (mph)", "Safe velocity (mph)", "Acceleration (mph/turn)",
280 "Aerodynamics coeff", "Rolling coeff", "Static Drag", "Offroad %"
281 };
282 auto dump = [&rows]( const vproto_id & obj ) {
283 vehicle veh_empty( obj, 0, 0 );
284 vehicle veh_fueled( obj, 100, 0 );
285
286 std::vector<std::string> r;
287 r.push_back( veh_empty.name );
288 r.push_back( std::to_string( to_kilogram( veh_empty.total_mass() ) ) );
289 r.push_back( std::to_string( to_kilogram( veh_fueled.total_mass() ) ) );
290 r.push_back( std::to_string( veh_fueled.max_velocity() / 100 ) );
291 r.push_back( std::to_string( veh_fueled.safe_velocity() / 100 ) );
292 r.push_back( std::to_string( veh_fueled.acceleration() / 100 ) );
293 r.push_back( std::to_string( veh_fueled.coeff_air_drag() ) );
294 r.push_back( std::to_string( veh_fueled.coeff_rolling_drag() ) );
295 r.push_back( std::to_string( veh_fueled.static_drag( false ) ) );
296 r.push_back( std::to_string( static_cast<int>( 50 *
297 veh_fueled.k_traction( veh_fueled.wheel_area() ) ) ) );
298 rows.push_back( r );
299 };
300 for( auto &e : vehicle_prototype::get_all() ) {
301 dump( e );
302 }
303
304 } else if( what == "VPART" ) {
305 header = {
306 "Name", "Location", "Weight", "Size"
307 };
308 auto dump = [&rows]( const vpart_info & obj ) {
309 std::vector<std::string> r;
310 r.push_back( obj.name() );
311 r.push_back( obj.location );
312 int w = std::ceil( to_gram( item( obj.item ).weight() ) / 1000.0 );
313 r.push_back( std::to_string( w ) );
314 r.push_back( std::to_string( obj.size / units::legacy_volume_factor ) );
315 rows.push_back( r );
316 };
317 for( const auto &e : vpart_info::all() ) {
318 dump( e.second );
319 }
320
321 } else {
322 std::cerr << "unknown argument: " << what << std::endl;
323 return false;
324 }
325
326 rows.erase( std::remove_if( rows.begin(), rows.end(), []( const std::vector<std::string> &e ) {
327 return e.empty();
328 } ), rows.end() );
329
330 if( scol >= 0 ) {
331 std::sort( rows.begin(), rows.end(), [&scol]( const std::vector<std::string> &lhs,
332 const std::vector<std::string> &rhs ) {
333 return localized_compare( lhs[ scol ], rhs[ scol ] );
334 } );
335 }
336
337 rows.erase( std::unique( rows.begin(), rows.end() ), rows.end() );
338
339 switch( mode ) {
340 case dump_mode::TSV:
341 rows.insert( rows.begin(), header );
342 for( const auto &r : rows ) {
343 // NOLINTNEXTLINE(cata-text-style): using tab to align the output
344 std::copy( r.begin(), r.end() - 1, std::ostream_iterator<std::string>( std::cout, "\t" ) );
345 std::cout << r.back() << "\n";
346 }
347 break;
348
349 case dump_mode::HTML:
350 std::cout << "<table>";
351
352 std::cout << "<thead>";
353 std::cout << "<tr>";
354 for( const auto &col : header ) {
355 std::cout << "<th>" << col << "</th>";
356 }
357 std::cout << "</tr>";
358 std::cout << "</thead>";
359
360 std::cout << "<tdata>";
361 for( const auto &r : rows ) {
362 std::cout << "<tr>";
363 for( const auto &col : r ) {
364 std::cout << "<td>" << col << "</td>";
365 }
366 std::cout << "</tr>";
367 }
368 std::cout << "</tdata>";
369
370 std::cout << "</table>";
371 break;
372 }
373
374 return true;
375}
body_part get_body_part_token(const std::string &id)
Returns the matching body_part token from the corresponding body_part string.
Definition: bodypart.cpp:180
body_part
Definition: bodypart.h:39
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
Definition: skill.h:33
static std::vector< Skill > skills
Definition: skill.h:49
const skill_id & ident() const
Definition: skill.h:65
bool load_packs(const std::string &msg, const std::vector< mod_id > &packs, loading_ui &ui)
Load content packs.
Definition: game.cpp:2965
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4768
void put_in(const item &payload)
Puts the given item into this one, no checks are performed.
Definition: item.cpp:981
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:582
std::set< constrecipe * >::const_iterator begin() const
std::set< constrecipe * >::const_iterator end() const
void include(const recipe *r, int custom_difficulty=-1)
Include a recipe to the subset.
Definition: recipe.h:35
An NPC with standard stats.
Definition: npc.h:1394
static const std::map< vitamin_id, vitamin > & all()
Get all currently loaded vitamins.
Definition: vitamin.cpp:98
static const std::map< vpart_id, vpart_info > & all()
Definition: veh_type.cpp:694
static const std::string flag_VARSIZE("VARSIZE")
std::unique_ptr< Item_factory > item_controller
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1574
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
constexpr value_type to_gram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:67
constexpr value_type to_kilogram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:73
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:679
recipe_dictionary recipe_dict
float total_damage() const
Definition: damage.cpp:75
std::vector< damage_unit >::iterator begin()
Definition: damage.cpp:120
bool empty() const
Definition: damage.cpp:88
Default (or randomized) charges except if counted by charges then only one charge.
Definition: item.h:196
Definition: itype.h:837
static std::vector< vproto_id > get_all()
Definition: veh_type.cpp:1157
string_id< MOD_INFORMATION > mod_id
Definition: type_id.h:91

References _, vitamin::all(), item::ammo_capacity(), item::ammo_default(), item::ammo_set(), damage_instance::begin(), item::covers(), damage_instance::empty(), enumerate_as_string(), DynamicDataLoader::finalize_loaded_data(), flag_VARSIZE(), g, get_body_part_token(), DynamicDataLoader::get_instance(), itype::gun, item::has_flag(), Skill::ident(), recipe_subset::include(), item_controller, itype_id, units::legacy_volume_factor, load_core_data(), load_packs(), anonymous_namespace{overmap_location.cpp}::locations, item::magazine_default(), item::magazine_integral(), none, num_bp, item::put_in(), recipe_dict, item::set_flag(), Skill::skills, units::to_gram(), to_string(), damage_instance::total_damage(), iexamine::transform(), calendar::turn, and item::type.

◆ events()

event_bus & game::events ( )

Definition at line 3075 of file game.cpp.

3076{
3077 return *event_bus_ptr;
3078}
pimpl< event_bus > event_bus_ptr
Definition: game.h:1001

References event_bus_ptr.

Referenced by cleanup_at_end(), and game().

◆ exam_vehicle()

void game::exam_vehicle ( vehicle veh,
const point cp = point_zero 
)

open vehicle interaction screen

Definition at line 5270 of file game.cpp.

5271{
5272 if( veh.magic ) {
5273 add_msg( m_info, _( "This is your %s" ), veh.name );
5274 return;
5275 }
5276 auto act = veh_interact::run( veh, c );
5277 if( act ) {
5278 u.moves = 0;
5280 }
5281}
static player_activity run(vehicle &veh, const point &p)
bool magic
Definition: vehicle.h:1809
constexpr double c
Definition: magic.cpp:1031
activity_id act
Definition: sounds.cpp:75

References _, act, add_msg(), Character::assign_activity(), c, m_info, vehicle::magic, Creature::moves, vehicle::name, veh_interact::run(), and u.

◆ examine() [1/2]

void game::examine ( )
private

Definition at line 5650 of file game.cpp.

5651{
5652 // if we are driving a vehicle, examine the
5653 // current tile without asking.
5654 const optional_vpart_position vp = m.veh_at( u.pos() );
5655 if( vp && vp->vehicle().player_in_control( u ) ) {
5656 examine( u.pos() );
5657 return;
5658 }
5659
5660 const cata::optional<tripoint> examp_ = choose_adjacent_highlight( _( "Examine where?" ),
5661 _( "There is nothing that can be examined nearby." ),
5662 ACTION_EXAMINE, false );
5663 if( !examp_ ) {
5664 return;
5665 }
5666 u.manual_examine = true;
5667 examine( *examp_ );
5668 u.manual_examine = false;
5669}
cata::optional< tripoint > choose_adjacent_highlight(const std::string &message, const std::string &failure_message, const action_id action, bool allow_vertical)
Request player input of adjacent tile with highlighting, possibly on different z-level.
Definition: action.cpp:1012
@ ACTION_EXAMINE
Examine or pick up items from adjacent square.
Definition: action.h:105
void examine()
Definition: game.cpp:5650
bool manual_examine
Definition: player.h:697

References _, ACTION_EXAMINE, choose_adjacent_highlight(), examine(), m, player::manual_examine, Character::pos(), u, and map::veh_at().

Referenced by examine(), and handle_action().

◆ examine() [2/2]

void game::examine ( const tripoint p)
private

Definition at line 5737 of file game.cpp.

5738{
5739 if( disable_robot( examp ) ) {
5740 return;
5741 }
5742
5743 Creature *c = critter_at( examp );
5744 if( c != nullptr ) {
5745 monster *mon = dynamic_cast<monster *>( c );
5746 if( mon != nullptr ) {
5747 add_msg( _( "There is a %s." ), mon->get_name() );
5748 if( mon->has_effect( effect_pet ) && !u.is_mounted() ) {
5749 if( monexamine::pet_menu( *mon ) ) {
5750 return;
5751 }
5752 } else if( mon->has_flag( MF_RIDEABLE_MECH ) && !mon->has_effect( effect_pet ) ) {
5753 if( monexamine::mech_hack( *mon ) ) {
5754 return;
5755 }
5756 } else if( mon->has_flag( MF_PAY_BOT ) ) {
5757 if( monexamine::pay_bot( *mon ) ) {
5758 return;
5759 }
5760 } else if( mon->attitude_to( u ) == Creature::A_FRIENDLY && !u.is_mounted() ) {
5761 if( monexamine::mfriend_menu( *mon ) ) {
5762 return;
5763 }
5764 }
5765 } else if( u.is_mounted() ) {
5766 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5767 }
5768 npc *np = dynamic_cast<npc *>( c );
5769 if( np != nullptr && !u.is_mounted() ) {
5770 if( npc_menu( *np ) ) {
5771 return;
5772 }
5773 } else if( np != nullptr && u.is_mounted() ) {
5774 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5775 }
5776 }
5777
5778 const optional_vpart_position vp = m.veh_at( examp );
5779 if( vp && u.is_mounted() ) {
5780 if( !u.mounted_creature->has_flag( MF_RIDEABLE_MECH ) ) {
5781 add_msg( m_warning, _( "You cannot interact with a vehicle while mounted." ) );
5782 } else {
5783 vp->vehicle().interact_with( examp, vp->part_index() );
5784 return;
5785 }
5786 } else if( vp && !u.is_mounted() ) {
5787 vp->vehicle().interact_with( examp, vp->part_index() );
5788 return;
5789 }
5790
5791 if( m.has_flag( "CONSOLE", examp ) && !u.is_mounted() ) {
5792 use_computer( examp );
5793 return;
5794 } else if( m.has_flag( "CONSOLE", examp ) && u.is_mounted() ) {
5795 add_msg( m_warning, _( "You cannot use a console while mounted." ) );
5796 }
5797 const furn_t &xfurn_t = m.furn( examp ).obj();
5798 const ter_t &xter_t = m.ter( examp ).obj();
5799
5800 const tripoint player_pos = u.pos();
5801
5802 if( m.has_furn( examp ) && !u.is_mounted() ) {
5803 xfurn_t.examine( u, examp );
5804 } else if( m.has_furn( examp ) && u.is_mounted() ) {
5805 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5806 } else {
5807 if( !u.is_mounted() ) {
5808 xter_t.examine( u, examp );
5809 } else if( u.is_mounted() && xter_t.examine == &iexamine::none ) {
5810 xter_t.examine( u, examp );
5811 } else {
5812 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5813 }
5814 }
5815
5816 // Did the player get moved? Bail out if so; our examp probably
5817 // isn't valid anymore.
5818 if( player_pos != u.pos() ) {
5819 return;
5820 }
5821
5822 bool none = true;
5823 if( xter_t.examine != &iexamine::none || xfurn_t.examine != &iexamine::none ) {
5824 none = false;
5825 }
5826
5827 if( !m.tr_at( examp ).is_null() && !u.is_mounted() ) {
5828 iexamine::trap( u, examp );
5829 } else if( !m.tr_at( examp ).is_null() && u.is_mounted() ) {
5830 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5831 }
5832
5833 // In case of teleport trap or somesuch
5834 if( player_pos != u.pos() ) {
5835 return;
5836 }
5837
5838 // Feedback for fire lasting time, this can be judged while mounted
5839 const std::string fire_fuel = get_fire_fuel_string( examp );
5840 if( !fire_fuel.empty() ) {
5841 add_msg( fire_fuel );
5842 }
5843
5844 if( m.has_flag( "SEALED", examp ) ) {
5845 if( none ) {
5846 if( m.has_flag( "UNSTABLE", examp ) ) {
5847 add_msg( _( "The %s is too unstable to remove anything." ), m.name( examp ) );
5848 } else {
5849 add_msg( _( "The %s is firmly sealed." ), m.name( examp ) );
5850 }
5851 }
5852 } else {
5853 //examp has no traps, is a container and doesn't have a special examination function
5854 if( m.tr_at( examp ).is_null() && m.i_at( examp ).empty() &&
5855 m.has_flag( "CONTAINER", examp ) && none ) {
5856 add_msg( _( "It is empty." ) );
5857 } else if( ( m.has_flag( TFLAG_FIRE_CONTAINER, examp ) &&
5858 xfurn_t.examine == &iexamine::fireplace ) ||
5859 xfurn_t.examine == &iexamine::workbench ) {
5860 return;
5861 } else {
5863 if( !u.is_mounted() ) {
5864 pickup::pick_up( examp, 0 );
5865 }
5866 }
5867 }
5868}
shared_ptr_fast< monster > mounted_creature
Definition: character.h:1614
@ A_FRIENDLY
Definition: creature.h:171
void use_computer(const tripoint &p)
Checks to see if a player can use a computer (not illiterate, etc.) and uses if able.
Definition: game.cpp:4800
bool disable_robot(const tripoint &p)
If there is a robot (that can be disabled), query the player and try to disable it.
Definition: game.cpp:9180
bool npc_menu(npc &who)
Returns true if the menu handled stuff and player shouldn't do anything else.
Definition: game.cpp:5541
bool empty() const
Definition: item_stack.cpp:15
bool has_furn(const tripoint &p) const
Definition: map.cpp:1354
const trap & tr_at(const tripoint &p) const
Definition: map.cpp:5129
ter_id ter(const tripoint &p) const
Definition: map.cpp:1509
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
Definition: monster.cpp:1020
std::string get_name() const override
Definition: monster.cpp:487
static const efftype_id effect_pet("pet")
static std::string get_fire_fuel_string(const tripoint &examp)
Definition: game.cpp:5671
@ TFLAG_FIRE_CONTAINER
Definition: mapdata.h:293
void fireplace(player &p, const tripoint &examp)
Definition: iexamine.cpp:2854
void workbench(player &p, const tripoint &examp)
Definition: iexamine.cpp:6008
void none(player &p, const tripoint &examp)
Nothing player can interact with here.
Definition: iexamine.cpp:241
void trap(player &p, const tripoint &examp)
Definition: iexamine.cpp:3739
bool pet_menu(monster &z)
Definition: monexamine.cpp:64
bool mech_hack(monster &z)
Definition: monexamine.cpp:373
bool mfriend_menu(monster &z)
Definition: monexamine.cpp:445
bool pay_bot(monster &z)
Definition: monexamine.cpp:405
void pick_up(const tripoint &p, int min, from_where get_items_from=prompt)
Pick up items; 'g' or ',' or via examine()
Definition: pickup.cpp:571
iexamine_function examine
Definition: mapdata.h:398
Definition: mapdata.h:457
bool is_null() const
Whether this is the null-traps, aka no trap at all.
Definition: trap.cpp:245

References _, Creature::A_FRIENDLY, add_msg(), monster::attitude_to(), c, critter_at(), disable_robot(), effect_pet, item_stack::empty(), map_data_common_t::examine, iexamine::fireplace(), map::furn(), get_fire_fuel_string(), monster::get_name(), Creature::has_effect(), map::has_flag(), monster::has_flag(), map::has_furn(), map::i_at(), Character::is_mounted(), trap::is_null(), m, m_warning, monexamine::mech_hack(), MF_PAY_BOT, MF_RIDEABLE_MECH, monexamine::mfriend_menu(), Character::mounted_creature, map::name(), none, iexamine::none(), npc_menu(), int_id< T >::obj(), monexamine::pay_bot(), monexamine::pet_menu(), pickup::pick_up(), Character::pos(), sounds::process_sound_markers(), map::ter(), TFLAG_FIRE_CONTAINER, map::tr_at(), iexamine::trap(), u, use_computer(), map::veh_at(), and iexamine::workbench().

◆ extended_description()

void game::extended_description ( const tripoint p)

Long description of (visible) things at tile.

Definition at line 50 of file descriptions.cpp.

51{
53 const int top = 3;
54 int width = 0;
55 catacurses::window w_head;
56 catacurses::window w_main;
57 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
58 const int left = 0;
59 const int right = TERMX;
60 const int bottom = TERMY;
61 width = right - left;
62 const int height = bottom - top;
63 w_head = catacurses::newwin( top, TERMX, point_zero );
64 w_main = catacurses::newwin( height, width, point( left, top ) );
65 ui.position( point_zero, point( TERMX, TERMY ) );
66 } );
67 ui.mark_resize();
68
69 // Default to critter (if any), furniture (if any), then terrain.
71 if( seen_critter( *this, p ) != nullptr ) {
73 } else if( get_map().has_furn( p ) ) {
75 }
76
77 std::string action;
78 input_context ctxt( "EXTENDED_DESCRIPTION" );
79 ctxt.register_action( "CREATURE" );
80 ctxt.register_action( "FURNITURE" );
81 ctxt.register_action( "TERRAIN" );
82 ctxt.register_action( "CONFIRM" );
83 ctxt.register_action( "QUIT" );
84 ctxt.register_action( "HELP_KEYBINDINGS" );
85
86 ui.on_redraw( [&]( const ui_adaptor & ) {
87 werase( w_head );
89 _( "[%s] describe creatures, [%s] describe furniture, "
90 "[%s] describe terrain, [%s] close." ),
91 ctxt.get_desc( "CREATURE" ), ctxt.get_desc( "FURNITURE" ),
92 ctxt.get_desc( "TERRAIN" ), ctxt.get_desc( "QUIT" ) );
93
94 // Set up line drawings
95 for( int i = 0; i < TERMX; i++ ) {
96 mvwputch( w_head, point( i, top - 1 ), c_white, LINE_OXOX );
97 }
98
99 wnoutrefresh( w_head );
100
101 std::string desc;
102 // Allow looking at invisible tiles - player may want to examine hallucinations etc.
103 switch( cur_target ) {
105 const Creature *critter = seen_critter( *this, p );
106 if( critter != nullptr ) {
107 desc = critter->extended_description();
108 } else {
109 desc = _( "You do not see any creature here." );
110 }
111 }
112 break;
114 if( !u.sees( p ) || !m.has_furn( p ) ) {
115 desc = _( "You do not see any furniture here." );
116 } else {
117 const furn_id fid = m.furn( p );
118 desc = fid.obj().extended_description();
119 }
120 break;
122 if( !u.sees( p ) ) {
123 desc = _( "You can't see the terrain here." );
124 } else {
125 const ter_id tid = m.ter( p );
126 desc = tid.obj().extended_description();
127 }
128 break;
129 }
130
131 std::string signage = m.get_signage( p );
132 if( !signage.empty() ) {
133 // NOLINTNEXTLINE(cata-text-style): the question mark does not end a sentence
134 desc += u.has_trait( trait_ILLITERATE ) ? _( "\nSign: ???" ) : string_format( _( "\nSign: %s" ),
135 signage );
136 }
137
138 werase( w_main );
139 fold_and_print_from( w_main, point_zero, width, 0, c_light_gray, desc );
140 wnoutrefresh( w_main );
141 } );
142
143 do {
145 action = ctxt.handle_input();
146 if( action == "CREATURE" ) {
147 cur_target = description_target::creature;
148 } else if( action == "FURNITURE" ) {
150 } else if( action == "TERRAIN" ) {
151 cur_target = description_target::terrain;
152 }
153 } while( action != "CONFIRM" && action != "QUIT" );
154}
virtual std::string extended_description() const =0
friend map & get_map()
Definition: map.cpp:141
std::string get_signage(const tripoint &p) const
Definition: map.cpp:3987
static const trait_id trait_ILLITERATE("ILLITERATE")
static const Creature * seen_critter(const game &g, const tripoint &p)
description_target
int fold_and_print_from(const catacurses::window &w, const point &begin, int width, int begin_line, const nc_color &base_color, const std::string &text)
Like fold_and_print, but starts the output with the N-th line of the folded string.
Definition: output.cpp:311
std::string extended_description() const

References _, action, c_light_gray, c_white, creature, map_data_common_t::extended_description(), Creature::extended_description(), fold_and_print_from(), map::furn(), furniture, input_context::get_desc(), get_map, map::get_signage(), input_context::handle_input(), map::has_furn(), Character::has_trait(), left, LINE_OXOX, m, mvwprintz(), mvwputch(), catacurses::newwin(), int_id< T >::obj(), point_zero, ui_manager::redraw(), input_context::register_action(), right, seen_critter(), Character::sees(), string_format(), map::ter(), TERMX, TERMY, terrain, trait_ILLITERATE, u, catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by look_around().

◆ find_nearby_items()

std::vector< map_item_stack > game::find_nearby_items ( int  iRadius)
private

Definition at line 7185 of file game.cpp.

7186{
7187 std::map<std::string, map_item_stack> temp_items;
7188 std::vector<map_item_stack> ret;
7189 std::vector<std::string> item_order;
7190
7191 if( u.is_blind() ) {
7192 return ret;
7193 }
7194
7195 for( auto &points_p_it : closest_points_first( u.pos(), iRadius ) ) {
7196 if( points_p_it.y >= u.posy() - iRadius && points_p_it.y <= u.posy() + iRadius &&
7197 u.sees( points_p_it ) &&
7198 m.sees_some_items( points_p_it, u ) ) {
7199
7200 for( auto &elem : m.i_at( points_p_it ) ) {
7201 const std::string name = elem.tname();
7202 const tripoint relative_pos = points_p_it - u.pos();
7203
7204 if( std::find( item_order.begin(), item_order.end(), name ) == item_order.end() ) {
7205 item_order.push_back( name );
7206 temp_items[name] = map_item_stack( &elem, relative_pos );
7207 } else {
7208 temp_items[name].add_at_pos( &elem, relative_pos );
7209 }
7210 }
7211 }
7212 }
7213
7214 for( auto &elem : item_order ) {
7215 ret.push_back( temp_items[elem] );
7216 }
7217
7218 return ret;
7219}
bool is_blind() const
Returns true if the player isn't able to see.
Definition: character.cpp:6214
std::vector< coords::coord_point< Point, Origin, Scale > > closest_points_first(const coords::coord_point< Point, Origin, Scale > &loc, int min_dist, int max_dist)
Definition: coordinates.h:596

References closest_points_first(), detail::find(), map::i_at(), Character::is_blind(), m, om_direction::name(), Character::pos(), Character::posy(), cata::hash64_detail::ret, Character::sees(), map::sees_some_items(), and u.

Referenced by list_items_monsters().

◆ find_npc()

npc * game::find_npc ( character_id  id)

Find the npc with the given ID.

Returns NULL if the npc could not be found. Searches all loaded overmaps.

Definition at line 1951 of file game.cpp.

1952{
1953 return overmap_buffer.find_npc( id ).get();
1954}

References overmapbuffer::find_npc(), and overmap_buffer.

Referenced by critter_by_id().

◆ find_or_make_stairs()

cata::optional< tripoint > game::find_or_make_stairs ( map mp,
int  z_after,
bool &  rope_ladder,
bool  peeking 
)

Returns the other end of the stairs (if any).

May query, affect u etc.

Definition at line 10943 of file game.cpp.

10945{
10946 const int omtilesz = SEEX * 2;
10947 real_coords rc( m.getabs( point( u.posx(), u.posy() ) ) );
10948 tripoint omtile_align_start( m.getlocal( rc.begin_om_pos() ), z_after );
10949 tripoint omtile_align_end( omtile_align_start + point( -1 + omtilesz, -1 + omtilesz ) );
10950
10951 // Try to find the stairs.
10953 int best = INT_MAX;
10954 const int movez = z_after - get_levz();
10955 const bool going_down_1 = movez == -1;
10956 const bool going_up_1 = movez == 1;
10957 // If there are stairs on the same x and y as we currently are, use those
10958 if( going_down_1 && mp.has_flag( TFLAG_GOES_UP, u.pos() + tripoint_below ) ) {
10959 stairs.emplace( u.pos() + tripoint_below );
10960 }
10961 if( going_up_1 && mp.has_flag( TFLAG_GOES_DOWN, u.pos() + tripoint_above ) ) {
10962 stairs.emplace( u.pos() + tripoint_above );
10963 }
10964 // We did not find stairs directly above or below, so search the map for them
10965 if( !stairs.has_value() ) {
10966 for( const tripoint &dest : m.points_in_rectangle( omtile_align_start, omtile_align_end ) ) {
10967 if( rl_dist( u.pos(), dest ) <= best &&
10968 ( ( going_down_1 && mp.has_flag( TFLAG_GOES_UP, dest ) ) ||
10969 ( going_up_1 && ( mp.has_flag( TFLAG_GOES_DOWN, dest ) ||
10970 mp.ter( dest ) == t_manhole_cover ) ) ||
10971 ( ( movez == 2 || movez == -2 ) && mp.ter( dest ) == t_elevator ) ) ) {
10972 stairs.emplace( dest );
10973 best = rl_dist( u.pos(), dest );
10974 }
10975 }
10976 }
10977
10978 if( stairs.has_value() ) {
10979 if( Creature *blocking_creature = critter_at( stairs.value() ) ) {
10980 npc *guy = dynamic_cast<npc *>( blocking_creature );
10981 monster *mon = dynamic_cast<monster *>( blocking_creature );
10982 bool would_move = ( guy && !guy->is_enemy() ) || ( mon && mon->friendly == -1 );
10983 bool can_displace = find_empty_spot_nearby( *stairs ).has_value();
10984 std::string cr_name = blocking_creature->get_name();
10985 std::string msg;
10986 if( guy ) {
10987 //~ %s is the name of hostile NPC
10988 msg = string_format( _( "%s is in the way!" ), cr_name );
10989 } else {
10990 //~ %s is some monster
10991 msg = string_format( _( "There's a %s in the way!" ), cr_name );
10992 }
10993
10994 if( ( peeking && !would_move ) || !can_displace || ( !would_move && !query_yn(
10995 //~ %s is a warning about monster/hostile NPC in the way, e.g. "There's a zombie in the way!"
10996 _( "%s Attempt to push past? You may have to fight your way back up." ), msg ) ) ) {
10997 add_msg( msg );
10998 return cata::nullopt;
10999 }
11000 }
11001 return stairs;
11002 }
11003
11004 // No stairs found! Try to make some
11005 rope_ladder = false;
11006 stairs.emplace( u.pos() );
11007 stairs->z = z_after;
11008 // Check the destination area for lava.
11009 if( mp.ter( *stairs ) == t_lava ) {
11010 if( movez < 0 &&
11011 !query_yn(
11012 _( "There is a LOT of heat coming out of there, even the stairs have melted away. Jump down? You won't be able to get back up." ) ) ) {
11013 return cata::nullopt;
11014 } else if( movez > 0 &&
11015 !query_yn(
11016 _( "There is a LOT of heat coming out of there. Push through the half-molten rocks and ascend? You will not be able to get back down." ) ) ) {
11017 return cata::nullopt;
11018 }
11019
11020 return stairs;
11021 }
11022
11023 if( movez > 0 ) {
11024 if( !mp.has_flag( "GOES_DOWN", *stairs ) ) {
11025 if( !query_yn( _( "You may be unable to return back down these stairs. Continue up?" ) ) ) {
11026 return cata::nullopt;
11027 }
11028 }
11029 // Manhole covers need this to work
11030 // Maybe require manhole cover here and fail otherwise?
11031 return stairs;
11032 }
11033
11034 if( mp.impassable( *stairs ) ) {
11035 popup( _( "Halfway down, the way down becomes blocked off." ) );
11036 return cata::nullopt;
11037 }
11038
11039 if( u.has_trait( trait_id( "WEB_RAPPEL" ) ) ) {
11040 if( query_yn( _( "There is a sheer drop halfway down. Web-descend?" ) ) ) {
11041 rope_ladder = true;
11042 if( ( rng( 4, 8 ) ) < u.get_skill_level( skill_dodge ) ) {
11043 add_msg( _( "You attach a web and dive down headfirst, flipping upright and landing on your feet." ) );
11044 } else {
11045 add_msg( _( "You securely web up and work your way down, lowering yourself safely." ) );
11046 }
11047 } else {
11048 return cata::nullopt;
11049 }
11050 } else if( u.has_trait( trait_VINES2 ) || u.has_trait( trait_VINES3 ) ) {
11051 if( query_yn( _( "There is a sheer drop halfway down. Use your vines to descend?" ) ) ) {
11052 if( u.has_trait( trait_VINES2 ) ) {
11053 if( query_yn( _( "Detach a vine? It'll hurt, but you'll be able to climb back up…" ) ) ) {
11054 rope_ladder = true;
11055 add_msg( m_bad, _( "You descend on your vines, though leaving a part of you behind stings." ) );
11056 u.mod_pain( 5 );
11057 u.apply_damage( nullptr, bodypart_id( "torso" ), 5 );
11058 u.mod_stored_nutr( 10 );
11059 u.mod_thirst( 10 );
11060 } else {
11061 add_msg( _( "You gingerly descend using your vines." ) );
11062 }
11063 } else {
11064 add_msg( _( "You effortlessly lower yourself and leave a vine rooted for future use." ) );
11065 rope_ladder = true;
11066 u.mod_stored_nutr( 10 );
11067 u.mod_thirst( 10 );
11068 }
11069 } else {
11070 return cata::nullopt;
11071 }
11072 } else if( u.has_amount( itype_grapnel, 1 ) ) {
11073 if( query_yn( _( "There is a sheer drop halfway down. Climb your grappling hook down?" ) ) ) {
11074 rope_ladder = true;
11076 } else {
11077 return cata::nullopt;
11078 }
11079 } else if( u.has_amount( itype_rope_30, 1 ) ) {
11080 if( query_yn( _( "There is a sheer drop halfway down. Climb your rope down?" ) ) ) {
11081 rope_ladder = true;
11083 } else {
11084 return cata::nullopt;
11085 }
11086 } else if( !query_yn( _( "There is a sheer drop halfway down. Jump?" ) ) ) {
11087 return cata::nullopt;
11088 }
11089
11090 return stairs;
11091}
int_id< body_part_type > bodypart_id
Definition: bodypart.h:23
void apply_damage(Creature *source, bodypart_id hurt, int dam, bool bypass_med=false) override
Actually hurt the player, hurts a body_part directly, no armor reduction.
Definition: character.cpp:8241
std::list< item > use_amount(itype_id it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: character.cpp:9441
virtual void mod_thirst(int nthirst)
Definition: character.cpp:4288
virtual void mod_stored_nutr(int nnutr)
Definition: character.cpp:4178
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3225
T & emplace(Args &&... args)
Definition: optional.h:143
constexpr bool has_value() const noexcept
Definition: optional.h:120
tripoint getlocal(const tripoint &p) const
Inverse of getabs.
Definition: map.cpp:8047
bool impassable(const tripoint &p) const
Definition: map.cpp:1806
tripoint_range< tripoint > points_in_rectangle(const tripoint &from, const tripoint &to) const
Definition: map.cpp:8380
bool is_enemy() const
Definition: npc.cpp:2040
void mod_pain(int npain) override
Modifies a pain value by player traits before passing it to Creature::mod_pain()
Definition: player.cpp:1092
static const trait_id trait_VINES2("VINES2")
static const skill_id skill_dodge("dodge")
static cata::optional< tripoint > find_empty_spot_nearby(const tripoint &pos)
Definition: game.cpp:10480
static const itype_id itype_rope_30("rope_30")
static const itype_id itype_grapnel("grapnel")
static const trait_id trait_VINES3("VINES3")
ter_id t_manhole_cover
Definition: mapdata.cpp:720
ter_id t_lava
Definition: mapdata.cpp:695
ter_id t_elevator
Definition: mapdata.cpp:723
@ TFLAG_GOES_DOWN
Definition: mapdata.h:308
@ TFLAG_GOES_UP
Definition: mapdata.h:309
static constexpr nullopt_t nullopt
Definition: optional.h:22
static constexpr tripoint tripoint_below
Definition: point.h:295
static constexpr tripoint tripoint_above
Definition: point.h:294

References _, add_msg(), Character::apply_damage(), real_coords::begin_om_pos(), critter_at(), cata::optional< T >::emplace(), find_empty_spot_nearby(), monster::friendly, get_levz(), Character::get_skill_level(), map::getabs(), map::getlocal(), visitable< T >::has_amount(), map::has_flag(), Character::has_trait(), cata::optional< T >::has_value(), map::impassable(), npc::is_enemy(), itype_grapnel, itype_rope_30, m, m_bad, player::mod_pain(), Character::mod_stored_nutr(), Character::mod_thirst(), cata::nullopt, map::points_in_rectangle(), popup(), Character::pos(), Character::posx(), Character::posy(), query_yn(), rl_dist(), rng(), SEEX, skill_dodge, string_format(), t_elevator, t_lava, t_manhole_cover, map::ter(), TFLAG_GOES_DOWN, TFLAG_GOES_UP, trait_VINES2, trait_VINES3, tripoint_above, tripoint_below, u, Character::use_amount(), and cata::optional< T >::value().

Referenced by vertical_move().

◆ fling_creature()

void game::fling_creature ( Creature c,
const units::angle dir,
float  flvel,
bool  controlled = false,
bool  suppress_map_update = false 
)

Flings the input creature in the given direction.

Definition at line 10305 of file game.cpp.

10307{
10308 if( c == nullptr ) {
10309 debugmsg( "game::fling_creature invoked on null target" );
10310 return;
10311 }
10312
10313 if( c->is_dead_state() ) {
10314 // Flinging a corpse causes problems, don't enable without testing
10315 return;
10316 }
10317
10318 if( c->is_hallucination() ) {
10319 // Don't fling hallucinations
10320 return;
10321 }
10322
10323 int steps = 0;
10324 bool thru = true;
10325 const bool is_u = ( c == &u );
10326 // Don't animate critters getting bashed if animations are off
10327 const bool animate = is_u || get_option<bool>( "ANIMATIONS" );
10328
10329 player *p = dynamic_cast<player *>( c );
10330
10331 tileray tdir( dir );
10332 int range = flvel / 10;
10333 tripoint pt = c->pos();
10334 while( range > 0 ) {
10335 c->underwater = false;
10336 // TODO: Check whenever it is actually in the viewport
10337 // or maybe even just redraw the changed tiles
10338 bool seen = is_u || u.sees( *c ); // To avoid redrawing when not seen
10339 tdir.advance();
10340 pt.x = c->posx() + tdir.dx();
10341 pt.y = c->posy() + tdir.dy();
10342 float force = 0;
10343
10344 if( monster *const mon_ptr = critter_at<monster>( pt ) ) {
10345 monster &critter = *mon_ptr;
10346 // Approximate critter's "stopping power" with its max hp
10347 force = std::min<float>( 1.5f * critter.type->hp, flvel );
10348 const int damage = rng( force, force * 2.0f ) / 6;
10349 c->impact( damage, pt );
10350 // Multiply zed damage by 6 because no body parts
10351 const int zed_damage = std::max( 0,
10352 ( damage - critter.get_armor_bash( bodypart_id( "torso" ) ) ) * 6 );
10353 // TODO: Pass the "flinger" here - it's not the flung critter that deals damage
10354 critter.apply_damage( c, bodypart_id( "torso" ), zed_damage );
10355 critter.check_dead_state();
10356 if( !critter.is_dead() ) {
10357 thru = false;
10358 }
10359 } else if( m.impassable( pt ) ) {
10360 if( !m.veh_at( pt ).obstacle_at_part() ) {
10361 force = std::min<float>( m.bash_strength( pt ), flvel );
10362 } else {
10363 // No good way of limiting force here
10364 // Keep it 1 less than maximum to make the impact hurt
10365 // but to keep the target flying after it
10366 force = flvel - 1;
10367 }
10368 const int damage = rng( force, force * 2.0f ) / 9;
10369 c->impact( damage, pt );
10370 if( m.is_bashable( pt ) ) {
10371 // Only go through if we successfully make the tile passable
10372 m.bash( pt, flvel );
10373 thru = m.passable( pt );
10374 } else {
10375 thru = false;
10376 }
10377 }
10378
10379 // If the critter dies during flinging, moving it around causes debugmsgs
10380 if( c->is_dead_state() ) {
10381 return;
10382 }
10383
10384 flvel -= force;
10385 if( thru ) {
10386 if( p != nullptr ) {
10387 if( p->in_vehicle ) {
10388 m.unboard_vehicle( p->pos() );
10389 }
10390 // If we're flinging the player around, make sure the map stays centered on them.
10391 if( is_u && !suppress_map_update ) {
10392 update_map( pt.x, pt.y );
10393 } else {
10394 p->setpos( pt );
10395 }
10396 } else if( !critter_at( pt ) ) {
10397 // Dying monster doesn't always leave an empty tile (blob spawning etc.)
10398 // Just don't setpos if it happens - next iteration will do so
10399 // or the monster will stop a tile before the unpassable one
10400 c->setpos( pt );
10401 }
10402 } else {
10403 // Don't zero flvel - count this as slamming both the obstacle and the ground
10404 // although at lower velocity
10405 break;
10406 }
10407 range--;
10408 steps++;
10409 if( animate && ( seen || u.sees( *c ) ) ) {
10413 }
10414 }
10415
10416 // Fall down to the ground - always on the last reached tile
10417 if( !m.has_flag( "SWIMMABLE", c->pos() ) ) {
10418 const trap_id trap_under_creature = m.tr_at( c->pos() ).loadid;
10419 // Didn't smash into a wall or a floor so only take the fall damage
10420 if( thru && trap_under_creature == tr_ledge ) {
10421 m.creature_on_trap( *c, false );
10422 } else {
10423 // Fall on ground
10424 int force = rng( flvel, flvel * 2 ) / 9;
10425 if( controlled ) {
10426 force = std::max( force / 2 - 5, 0 );
10427 }
10428 if( force > 0 ) {
10429 int dmg = c->impact( force, c->pos() );
10430 // TODO: Make landing damage the floor
10431 m.bash( c->pos(), dmg / 4, false, false, false );
10432 }
10433 // Always apply traps to creature i.e. bear traps, tele traps etc.
10434 m.creature_on_trap( *c, false );
10435 }
10436 } else {
10437 c->underwater = true;
10438 if( is_u ) {
10439 if( controlled ) {
10440 add_msg( _( "You dive into water." ) );
10441 } else {
10442 add_msg( m_warning, _( "You fall into water." ) );
10443 }
10444 }
10445 }
10446}
void setpos(const tripoint &p) override
Definition: character.h:856
void check_dead_state()
This function checks the creatures is_dead_state and (if true) calls die.
Definition: creature.cpp:1833
point update_map(player &p)
Definition: game.cpp:11170
int bash_strength(const tripoint &p, bool allow_floor=false) const
Returns max_str of the furniture or terrain at p.
Definition: map.cpp:2458
bash_results bash(const tripoint &p, int str, bool silent=false, bool destroy=false, bool bash_floor=false, const vehicle *bashing_vehicle=nullptr)
Returns a pair where first is whether anything was smashed and second is if it was destroyed.
Definition: map.cpp:3520
void unboard_vehicle(const vpart_reference &, Character *passenger, bool dead_passenger=false)
Definition: map.cpp:1060
bool is_bashable(const tripoint &p, bool allow_floor=false) const
Returns true if there is a bashable vehicle part or the furn/terrain is bashable at p.
Definition: map.cpp:2423
void creature_on_trap(Creature &critter, bool may_avoid=true)
Apply trap effects to the creature, similar to creature_in_field.
Definition: map.cpp:8253
bool passable(const tripoint &p) const
Definition: map.cpp:1811
int get_armor_bash(bodypart_id bp) const override
Definition: monster.cpp:1855
bool is_dead() const
Definition: monster.cpp:2753
void apply_damage(Creature *source, bodypart_id bp, int dam, bool bypass_med=false) override
Definition: monster.cpp:1636
cata::optional< vpart_reference > obstacle_at_part() const
Definition: vehicle.cpp:2491
static const trap_str_id tr_ledge("tr_ledge")
void redraw_invalidated()
Definition: ui_manager.cpp:290
int hp
Definition: mtype.h:267
trap_id loadid
Definition: trap.h:88
int y
Definition: point.h:151
int x
Definition: point.h:150

References _, add_msg(), tileray::advance(), monster::apply_damage(), map::bash(), map::bash_strength(), c, Creature::check_dead_state(), map::creature_on_trap(), critter_at(), debugmsg, tileray::dx(), tileray::dy(), monster::get_armor_bash(), map::has_flag(), mtype::hp, map::impassable(), Character::in_vehicle, invalidate_main_ui_adaptor(), map::is_bashable(), monster::is_dead(), trap::loadid, m, m_warning, optional_vpart_position::obstacle_at_part(), map::passable(), Character::pos(), ui_manager::redraw_invalidated(), refresh_display(), rng(), Character::sees(), Character::setpos(), map::tr_at(), tr_ledge, monster::type, u, map::unboard_vehicle(), update_map(), map::veh_at(), tripoint::x, and tripoint::y.

Referenced by moving_vehicle_dismount().

◆ forced_door_closing()

bool game::forced_door_closing ( const tripoint p,
const ter_id door_type,
int  bash_dmg 
)

Definition at line 5283 of file game.cpp.

5284{
5285 // TODO: Z
5286 const int &x = p.x;
5287 const int &y = p.y;
5288 const std::string &door_name = door_type.obj().name();
5289 // sed when player/monsters are knocked back and when moving items out of the way
5290 point kb( x, y );
5291 const auto valid_location = [&]( const tripoint & p ) {
5292 return g->is_empty( p );
5293 };
5295 valid_location ) ) {
5296 kb.x = -pos->x + x + x;
5297 kb.y = -pos->y + y + y;
5298 }
5299 const tripoint kbp( kb, p.z );
5300 if( kbp == p ) {
5301 // can't pushback any creatures anywhere, that means the door can't close.
5302 return false;
5303 }
5304 const bool can_see = u.sees( tripoint( x, y, p.z ) );
5305 player *npc_or_player = critter_at<player>( tripoint( x, y, p.z ), false );
5306 if( npc_or_player != nullptr ) {
5307 if( bash_dmg <= 0 ) {
5308 return false;
5309 }
5310 if( npc_or_player->is_npc() && can_see ) {
5311 add_msg( _( "The %1$s hits the %2$s." ), door_name, npc_or_player->name );
5312 } else if( npc_or_player->is_player() ) {
5313 add_msg( m_bad, _( "The %s hits you." ), door_name );
5314 }
5315 if( npc_or_player->activity ) {
5316 npc_or_player->cancel_activity();
5317 }
5318 // TODO: make the npc angry?
5319 npc_or_player->hitall( bash_dmg, 0, nullptr );
5320 knockback( kbp, p, std::max( 1, bash_dmg / 10 ), -1, 1 );
5321 // TODO: perhaps damage/destroy the gate
5322 // if the npc was really big?
5323 }
5324 if( monster *const mon_ptr = critter_at<monster>( p ) ) {
5325 monster &critter = *mon_ptr;
5326 if( bash_dmg <= 0 ) {
5327 return false;
5328 }
5329 if( can_see ) {
5330 add_msg( _( "The %1$s hits the %2$s." ), door_name, critter.name() );
5331 }
5332 if( critter.type->size <= MS_SMALL ) {
5333 critter.die_in_explosion( nullptr );
5334 } else {
5335 critter.apply_damage( nullptr, bodypart_id( "torso" ), bash_dmg );
5336 critter.check_dead_state();
5337 }
5338 if( !critter.is_dead() && critter.type->size >= MS_HUGE ) {
5339 // big critters simply prevent the gate from closing
5340 // TODO: perhaps damage/destroy the gate
5341 // if the critter was really big?
5342 return false;
5343 }
5344 if( !critter.is_dead() ) {
5345 // Still alive? Move the critter away so the door can close
5346 knockback( kbp, p, std::max( 1, bash_dmg / 10 ), -1, 1 );
5347 if( critter_at( p ) ) {
5348 return false;
5349 }
5350 }
5351 }
5352 if( const optional_vpart_position vp = m.veh_at( p ) ) {
5353 if( bash_dmg <= 0 ) {
5354 return false;
5355 }
5356 vp->vehicle().damage( vp->part_index(), bash_dmg );
5357 if( m.veh_at( p ) ) {
5358 // Check again in case all parts at the door tile
5359 // have been destroyed, if there is still a vehicle
5360 // there, the door can not be closed
5361 return false;
5362 }
5363 }
5364 if( bash_dmg < 0 && !m.i_at( point( x, y ) ).empty() ) {
5365 return false;
5366 }
5367 if( bash_dmg == 0 ) {
5368 for( auto &elem : m.i_at( point( x, y ) ) ) {
5369 if( elem.made_of( LIQUID ) ) {
5370 // Liquids are OK, will be destroyed later
5371 continue;
5372 } else if( elem.volume() < 250_ml ) {
5373 // Dito for small items, will be moved away
5374 continue;
5375 }
5376 // Everything else prevents the door from closing
5377 return false;
5378 }
5379 }
5380
5381 m.ter_set( point( x, y ), door_type );
5382 if( m.has_flag( "NOITEM", point( x, y ) ) ) {
5383 map_stack items = m.i_at( point( x, y ) );
5384 for( map_stack::iterator it = items.begin(); it != items.end(); ) {
5385 if( it->made_of( LIQUID ) ) {
5386 it = items.erase( it );
5387 continue;
5388 }
5389 if( it->made_of( material_id( "glass" ) ) && one_in( 2 ) ) {
5390 if( can_see ) {
5391 add_msg( m_warning, _( "A %s shatters!" ), it->tname() );
5392 } else {
5393 add_msg( m_warning, _( "Something shatters!" ) );
5394 }
5395 it = items.erase( it );
5396 continue;
5397 }
5398 m.add_item_or_charges( kbp, *it );
5399 it = items.erase( it );
5400 }
5401 }
5402 return true;
5403}
int hitall(int dam, int vary, Creature *source)
Harms all body parts for dam, with armor reduction.
Definition: character.cpp:8509
void knockback(const tripoint &s, const tripoint &t, int force, int stun, int dam_mult)
Definition: game.cpp:4570
iterator erase(const_iterator it) override
Definition: map.cpp:147
bool ter_set(const tripoint &p, const ter_id &new_terrain)
Definition: map.cpp:1650
void die_in_explosion(Creature *source)
Definition: monster.cpp:1650
bool is_npc() const override
Definition: player.h:131
bool is_player() const override
Definition: player.h:114
@ MS_SMALL
Definition: creature.h:59
@ MS_HUGE
Definition: creature.h:62
@ LIQUID
Definition: enums.h:175
cata::optional< tripoint > random_point(const map &m, const std::function< bool(const tripoint &)> &predicate)
Same as other random_point with a range enclosing all valid points of the map.
std::string name() const
Definition: mapdata.cpp:511
m_size size
Definition: mtype.h:259

References _, Character::activity, map::add_item_or_charges(), add_msg(), monster::apply_damage(), item_stack::begin(), Character::cancel_activity(), Creature::check_dead_state(), critter_at(), monster::die_in_explosion(), item_stack::end(), map_stack::erase(), g, map::has_flag(), Character::hitall(), map::i_at(), monster::is_dead(), player::is_npc(), player::is_player(), knockback(), LIQUID, m, m_bad, m_warning, MS_HUGE, MS_SMALL, Character::name, map_data_common_t::name(), monster::name(), int_id< T >::obj(), one_in(), map::points_in_radius(), random_point(), Character::sees(), mtype::size, map::ter_set(), monster::type, u, map::veh_at(), point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

◆ gametype()

special_game_id game::gametype ( ) const

Definition at line 626 of file game.cpp.

627{
628 return gamemode ? gamemode->id() : SGAME_NULL;
629}
@ SGAME_NULL
Definition: enums.h:93

References gamemode, and SGAME_NULL.

◆ get_creature_if()

Creature * game::get_creature_if ( const std::function< bool(const Creature &)> &  pred)

Returns a creature matching a predicate.

Only living (not dead) creatures are checked. Returns nullptr if no creature matches the predicate. There is no guarantee which creature is returned when several creatures match.

Definition at line 12516 of file game.cpp.

12517{
12518 for( Creature &critter : all_creatures() ) {
12519 if( pred( critter ) ) {
12520 return &critter;
12521 }
12522 }
12523 return nullptr;
12524}

References all_creatures().

◆ get_creatures_if()

std::vector< Creature * > game::get_creatures_if ( const std::function< bool(const Creature &)> &  pred)

Returns all creatures matching a predicate.

Only living ( not dead ) creatures are checked ( and returned ). Returned pointers are never null.

Definition at line 12426 of file game.cpp.

12428{
12429 std::vector<Creature *> result;
12430 for( Creature &critter : all_creatures() ) {
12431 if( pred( critter ) ) {
12432 result.push_back( &critter );
12433 }
12434 }
12435 return result;
12436}

References all_creatures().

◆ get_cur_om()

overmap & game::get_cur_om ( ) const

The overmap which contains the center submap of the reality bubble.

Definition at line 12406 of file game.cpp.

12407{
12408 // The player is located in the middle submap of the map.
12410 const tripoint pos_om = sm_to_om_copy( sm );
12411 // TODO: fix point types
12412 return overmap_buffer.get( point_abs_om( pos_om.xy() ) );
12413}
tripoint get_abs_sub() const
return abs_sub
Definition: map.cpp:8057
overmap & get(const point_abs_om &)
Uses overmap coordinates, that means x and y are directly compared with the position of the overmap.
point sm_to_om_copy(const point &p)
coords::coord_point< point, coords::origin::abs, coords::om > point_abs_om
Definition: coordinates.h:483
static constexpr int HALF_MAPSIZE
constexpr scale sm
Definition: coordinates.h:31

References overmapbuffer::get(), map::get_abs_sub(), HALF_MAPSIZE, m, overmap_buffer, coords::sm, sm_to_om_copy(), and tripoint::xy().

Referenced by start_game().

◆ get_dangerous_tile()

std::vector< std::string > game::get_dangerous_tile ( const tripoint dest_loc) const

Definition at line 9263 of file game.cpp.

9264{
9265 std::vector<std::string> harmful_stuff;
9266 const auto fields_here = m.field_at( u.pos() );
9267 for( const auto &e : m.field_at( dest_loc ) ) {
9268 // warn before moving into a dangerous field except when already standing within a similar field
9269 if( u.is_dangerous_field( e.second ) && fields_here.find_field( e.first ) == nullptr ) {
9270 harmful_stuff.push_back( e.second.name() );
9271 }
9272 }
9273
9274 if( !u.is_blind() ) {
9275 const trap &tr = m.tr_at( dest_loc );
9276 const bool boardable = static_cast<bool>( m.veh_at( dest_loc ).part_with_feature( "BOARDABLE",
9277 true ) );
9278 // HACK: Hack for now, later ledge should stop being a trap
9279 // Note: in non-z-level mode, ledges obey different rules and so should be handled as regular traps
9280 if( tr.loadid == tr_ledge && m.has_zlevels() ) {
9281 if( !boardable ) {
9282 harmful_stuff.emplace_back( tr.name() );
9283 }
9284 } else if( tr.can_see( dest_loc, u ) && !tr.is_benign() && !boardable ) {
9285 harmful_stuff.emplace_back( tr.name() );
9286 }
9287
9288 static const std::set< body_part > sharp_bps = {
9291 };
9292
9293 const auto sharp_bp_check = [this]( body_part bp ) {
9294 return u.immune_to( bp, { DT_CUT, 10 } );
9295 };
9296
9297 if( m.has_flag( "ROUGH", dest_loc ) && !m.has_flag( "ROUGH", u.pos() ) && !boardable &&
9298 ( u.get_armor_bash( bodypart_id( "foot_l" ) ) < 5 ||
9299 u.get_armor_bash( bodypart_id( "foot_r" ) ) < 5 ) ) {
9300 harmful_stuff.emplace_back( m.name( dest_loc ) );
9301 } else if( m.has_flag( "SHARP", dest_loc ) && !m.has_flag( "SHARP", u.pos() ) && !( u.in_vehicle ||
9302 g->m.veh_at( dest_loc ) ) &&
9303 u.dex_cur < 78 && !std::all_of( sharp_bps.begin(), sharp_bps.end(), sharp_bp_check ) ) {
9304 harmful_stuff.emplace_back( m.name( dest_loc ) );
9305 }
9306
9307 }
9308
9309 return harmful_stuff;
9310}
@ bp_foot_l
Definition: bodypart.h:50
@ bp_leg_r
Definition: bodypart.h:49
@ bp_eyes
Definition: bodypart.h:42
@ bp_hand_l
Definition: bodypart.h:46
@ bp_arm_l
Definition: bodypart.h:44
@ bp_leg_l
Definition: bodypart.h:48
@ bp_hand_r
Definition: bodypart.h:47
@ bp_head
Definition: bodypart.h:41
@ bp_torso
Definition: bodypart.h:40
@ bp_mouth
Definition: bodypart.h:43
@ bp_foot_r
Definition: bodypart.h:51
@ bp_arm_r
Definition: bodypart.h:45
int dex_cur
Definition: character.h:305
int get_armor_bash(bodypart_id bp) const override
Returns overall bashing resistance for the body_part.
Definition: character.cpp:6842
bool is_dangerous_field(const field_entry &entry) const
Returns true if the given field entry is dangerous to us.
Definition: creature.cpp:196
const field & field_at(const tripoint &p) const
Get the fields that are here.
Definition: map.cpp:5291
bool has_zlevels() const
Definition: map.h:1657
cata::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2479
bool immune_to(body_part bp, damage_unit dam) const
Check if a given body part is immune to a given damage type.
Definition: player.cpp:1075
@ DT_CUT
Definition: damage.h:25
Definition: trap.h:86
std::string name() const
Definition: trap.cpp:177
bool can_see(const tripoint &pos, const Character &p) const
Can player/npc p see this kind of trap, either by their memory (they known there is the trap) or by t...
Definition: trap.cpp:223
bool is_benign() const
If true, this is not really a trap and there won't be any safety queries before stepping onto it (e....
Definition: trap.h:159

References bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, trap::can_see(), Character::dex_cur, DT_CUT, map::field_at(), g, Character::get_armor_bash(), map::has_flag(), map::has_zlevels(), player::immune_to(), Character::in_vehicle, trap::is_benign(), Character::is_blind(), Creature::is_dangerous_field(), trap::loadid, m, trap::name(), map::name(), optional_vpart_position::part_with_feature(), Character::pos(), map::tr_at(), tr_ledge, u, and map::veh_at().

Referenced by is_dangerous_tile(), prompt_dangerous_tile(), and walk_move().

◆ get_fishable_locations()

std::unordered_set< tripoint > game::get_fishable_locations ( int  distance,
const tripoint fish_pos 
)

Get the contiguous fishable locations starting at fish_pos, out to the specificed distance.

Parameters
distanceDistance around the fish_pos to examine for contiguous fishable locations.
fish_posThe location being fished.
Returns
A set of locations representing the valid contiguous fishable locations.

Definition at line 3957 of file game.cpp.

3958{
3959 // We're going to get the contiguous fishable terrain starting at
3960 // the provided fishing location (e.g. where a line was cast or a fish
3961 // trap was set), and then check whether or not fishable monsters are
3962 // actually in those locations. This will help us ensure that we're
3963 // getting our fish from the location that we're ACTUALLY fishing,
3964 // rather than just somewhere in the vicinity.
3965
3966 std::unordered_set<tripoint> visited;
3967
3968 const tripoint fishing_boundary_min( fish_pos + point( -distance, -distance ) );
3969 const tripoint fishing_boundary_max( fish_pos + point( distance, distance ) );
3970
3971 const inclusive_cuboid<tripoint> fishing_boundaries(
3972 fishing_boundary_min, fishing_boundary_max );
3973
3974 const auto get_fishable_terrain = [&]( tripoint starting_point,
3975 std::unordered_set<tripoint> &fishable_terrain ) {
3976 std::queue<tripoint> to_check;
3977 to_check.push( starting_point );
3978 while( !to_check.empty() ) {
3979 const tripoint current_point = to_check.front();
3980 to_check.pop();
3981
3982 // We've been here before, so bail.
3983 if( visited.find( current_point ) != visited.end() ) {
3984 continue;
3985 }
3986
3987 // This point is out of bounds, so bail.
3988 if( !fishing_boundaries.contains( current_point ) ) {
3989 continue;
3990 }
3991
3992 // Mark this point as visited.
3993 visited.emplace( current_point );
3994
3995 if( m.has_flag( "FISHABLE", current_point ) ) {
3996 fishable_terrain.emplace( current_point );
3997 to_check.push( current_point + point_south );
3998 to_check.push( current_point + point_north );
3999 to_check.push( current_point + point_east );
4000 to_check.push( current_point + point_west );
4001 }
4002 }
4003 return;
4004 };
4005
4006 // Starting at the provided location, get our fishable terrain
4007 // and populate a set with those locations which we'll then use
4008 // to determine if any fishable monsters are in those locations.
4009 std::unordered_set<tripoint> fishable_points;
4010 get_fishable_terrain( fish_pos, fishable_points );
4011
4012 return fishable_points;
4013}
static constexpr point point_west
Definition: point.h:282
static constexpr point point_south
Definition: point.h:280
static constexpr point point_north
Definition: point.h:276
static constexpr point point_east
Definition: point.h:278

References inclusive_cuboid< Tripoint, >::contains(), map::has_flag(), m, point_east, point_north, point_south, and point_west.

◆ get_fishable_monsters()

std::vector< monster * > game::get_fishable_monsters ( std::unordered_set< tripoint > &  fishable_locations)

Get the fishable monsters within the provided fishable locations.

Parameters
fishable_locationsA set of locations which are valid fishable terrain. Any fishable monsters are filtered by this collection to determine those which can actually be caught.
Returns
Fishable monsters within the specified fishable terrain.

Definition at line 4015 of file game.cpp.

4017{
4018 std::vector<monster *> unique_fish;
4019 for( monster &critter : all_monsters() ) {
4020 // If it is fishable...
4021 if( critter.has_flag( MF_FISHABLE ) ) {
4022 const tripoint critter_pos = critter.pos();
4023 // ...and it is in a fishable location.
4024 if( fishable_locations.find( critter_pos ) != fishable_locations.end() ) {
4025 unique_fish.push_back( &critter );
4026 }
4027 }
4028 }
4029
4030 return unique_fish;
4031}
@ MF_FISHABLE
Definition: mtype.h:142

References all_monsters(), and MF_FISHABLE.

◆ get_follower_list()

std::set< character_id > game::get_follower_list ( )

Get set of followers.

Definition at line 2048 of file game.cpp.

2049{
2050 return follower_ids;
2051}

References follower_ids.

◆ get_kill_tracker()

const kill_tracker & game::get_kill_tracker ( ) const

Definition at line 965 of file game.cpp.

966{
967 return *kill_tracker_ptr;
968}

References kill_tracker_ptr.

Referenced by cleanup_at_end(), death_screen(), handle_action(), and win().

◆ get_levx()

int game::get_levx ( ) const

The top left corner of the reality bubble (in submaps coordinates).

This is the same as map::abs_sub of the m map.

Definition at line 12391 of file game.cpp.

12392{
12393 return m.get_abs_sub().x;
12394}

References map::get_abs_sub(), m, and tripoint::x.

Referenced by create_starting_npcs(), load_npcs(), look_around(), save_cyborg(), spawn_hallucination(), vertical_move(), and vertical_shift().

◆ get_levy()

int game::get_levy ( ) const

Definition at line 12396 of file game.cpp.

12397{
12398 return m.get_abs_sub().y;
12399}

References map::get_abs_sub(), m, and tripoint::y.

Referenced by create_starting_npcs(), load_npcs(), look_around(), save_cyborg(), spawn_hallucination(), vertical_move(), and vertical_shift().

◆ get_levz()

◆ get_moves_since_last_save()

int game::get_moves_since_last_save ( ) const

Definition at line 7355 of file game.cpp.

7356{
7357 return moves_since_last_save;
7358}

References moves_since_last_save.

◆ get_npcs_if()

std::vector< npc * > game::get_npcs_if ( const std::function< bool(const npc &)> &  pred)

Definition at line 12438 of file game.cpp.

12439{
12440 std::vector<npc *> result;
12441 for( npc &guy : all_npcs() ) {
12442 if( pred( guy ) ) {
12443 result.push_back( &guy );
12444 }
12445 }
12446 return result;
12447}

References all_npcs().

Referenced by allies(), chat(), and validate_npc_followers().

◆ get_player_base_save_path()

std::string game::get_player_base_save_path ( ) const

Base path for saving player data.

Just add a suffix (unique for the thing you want to save) and use the resulting path. Example: save_ui_data(get_player_base_save_path()+".ui")

Definition at line 12526 of file game.cpp.

12527{
12528 return get_world_base_save_path() + "/" + base64_encode( u.name );
12529}
std::string base64_encode(const std::string &str)
std::string get_world_base_save_path() const
Base path for saving world data.
Definition: game.cpp:12531

References base64_encode(), get_world_base_save_path(), Character::name, and u.

Referenced by save_player_data().

◆ get_player_input()

input_context game::get_player_input ( std::string &  action)
private

Definition at line 238 of file handle_action.cpp.

239{
240 input_context ctxt;
241 if( uquit == QUIT_WATCH ) {
242 ctxt = input_context( "DEFAULTMODE" );
243 ctxt.set_iso( true );
244 // The list of allowed actions in death-cam mode in game::handle_action
245 // *INDENT-OFF*
246 for( const action_id id : {
259 } ) {
260 ctxt.register_action( action_ident( id ) );
261 }
262 // *INDENT-ON*
263 ctxt.register_action( "QUIT", to_translation( "Accept your fate" ) );
264 } else {
266 }
267
269
270 user_turn current_turn;
271
272
273 // Checking early if we will need to handle animations
274 // If we do not need to handle animations that will not change as long as the user has not selected an action
275 // and we can handle it like we are not animating.
276 weather_printable wPrint;
277 bool animate_weather = false;
278 bool animate_sct = false;
279 bool do_animations = [&]() {
280 if( get_option<bool>( "ANIMATIONS" ) ) {
281 const bool weather_has_anim = init_weather_anim( get_weather().weather_id, wPrint );
282
283 animate_weather = weather_has_anim && get_option<bool>( "ANIMATION_RAIN" );
284 animate_sct = !SCT.vSCT.empty() && uquit != QUIT_WATCH && get_option<bool>( "ANIMATION_SCT" );
285
286#if defined(TILES)
287 // Always animate, minimap and terrain may have animations to run
288 return true;
289#else
290 // Otherwise we need to see if we actually should animate.
291 // Minimap and Terrain never animate in !TILES
292 return animate_weather || animate_sct || uquit == QUIT_WATCH;
293#endif
294 }
295 return false;
296 }
297 ();
298
299 if( do_animations ) {
300 ctxt.set_timeout( 125 );
301
303 make_shared_fast<game::draw_callback_t>( [&]() {
304 if( animate_weather ) {
305 draw_weather( wPrint );
306 }
307 if( animate_sct ) {
308 draw_sct();
309 }
310 } );
311 add_draw_callback( animation_cb );
312 invalidate_main_ui_adaptor(); // We want to redraw at least once.
313
314 do {
315 if( animate_weather ) {
317 generate_weather_anim_frame( get_weather().weather_id, wPrint );
318 }
319 // don't bother calculating SCT if we won't show it
320 if( animate_sct ) {
322
324
325 //Check for creatures on all drawing positions and offset if necessary
326 for( auto iter = SCT.vSCT.rbegin(); iter != SCT.vSCT.rend(); ++iter ) {
327 const direction oCurDir = iter->getDirecton();
328 const int width = utf8_width( iter->getText() );
329 for( int i = 0; i < width; ++i ) {
330 tripoint tmp( iter->getPosX() + i, iter->getPosY(), get_levz() );
331 const Creature *critter = critter_at( tmp, true );
332
333 if( critter != nullptr && u.sees( *critter ) ) {
334 i = -1;
335 int iPos = iter->getStep() + iter->getStepOffset();
336 for( auto iter2 = iter; iter2 != SCT.vSCT.rend(); ++iter2 ) {
337 if( iter2->getDirecton() == oCurDir &&
338 iter2->getStep() + iter2->getStepOffset() <= iPos ) {
339 if( iter2->getType() == "hp" ) {
340 iter2->advanceStepOffset();
341 }
342
343 iter2->advanceStepOffset();
344 iPos = iter2->getStep() + iter2->getStepOffset();
345 }
346 }
347 }
348 }
349 }
350
351 // Stop animation when done
352 animate_sct = !SCT.vSCT.empty();
353 }
354 // We don't cache these checks as their result may change after 1st redraw
356 // TODO: we redraw *everything* just to animate a couple blinking dots
357 // on the minimap or a few tiles.
358 // This is far from ideal, and can probably be done much cheaper
359 // (update only part of the screen? draw static parts into a texture?)
361 }
362
363 std::unique_ptr<static_popup> deathcam_msg_popup;
364 if( uquit == QUIT_WATCH ) {
365 deathcam_msg_popup = std::make_unique<static_popup>();
366 deathcam_msg_popup
367 ->wait_message( c_red, _( "Press %s to accept your fate…" ), ctxt.get_desc( "QUIT" ) )
368 .on_top( true );
369 }
370
372 } while( handle_mouseview( ctxt, action ) && uquit != QUIT_WATCH
373 && ( action != "TIMEOUT" || !current_turn.has_timeout_elapsed() ) );
374 ctxt.reset_timeout();
375 } else {
378 SCT.vSCT.clear();
379
380 ctxt.set_timeout( 125 );
381 while( handle_mouseview( ctxt, action ) ) {
382 if( action == "TIMEOUT" && current_turn.has_timeout_elapsed() ) {
383 break;
384 }
385 }
386 ctxt.reset_timeout();
387 }
388
389 return ctxt;
390}
std::string action_ident(action_id act)
Lookup a unique string identifier for a given action ID.
Definition: action.cpp:67
action_id
Enumerates all discrete actions that can be performed by player.
Definition: action.h:22
@ ACTION_CENTER
Center the viewport on character.
Definition: action.h:77
@ ACTION_SHIFT_SW
Move viewport south-west.
Definition: action.h:89
@ ACTION_SHIFT_NW
Move viewport north-west.
Definition: action.h:93
@ ACTION_KEYBINDINGS
Display keybindings list.
Definition: action.h:255
@ ACTION_SHIFT_E
Move viewport east.
Definition: action.h:83
@ ACTION_TOGGLE_MAP_MEMORY
Toggle memorized tiles being shown.
Definition: action.h:75
@ ACTION_SHIFT_S
Move viewport south.
Definition: action.h:87
@ ACTION_SHIFT_SE
Move viewport south-east.
Definition: action.h:85
@ ACTION_LOOK
Toggle look mode.
Definition: action.h:119
@ ACTION_SHIFT_NE
Move viewport north-east.
Definition: action.h:81
@ ACTION_SHIFT_W
Move viewport west.
Definition: action.h:91
@ ACTION_SHIFT_N
Move viewport north.
Definition: action.h:79
bool terrain_requires_animation()
Definition: animation.cpp:1136
bool minimap_requires_animation()
Definition: animation.cpp:1127
void draw_sct()
Definition: animation.cpp:797
void draw_weather(const weather_printable &wPrint)
Definition: animation.cpp:756
void add_draw_callback(shared_ptr_fast< draw_callback_t > cb)
Definition: game.cpp:3370
bool handle_mouseview(input_context &ctxt, std::string &action)
Definition: game.cpp:2310
void set_timeout(int val)
Sets input polling timeout as appropriate for the current interface system.
Definition: input.cpp:1458
std::string get_desc(const std::string &action_descriptor, unsigned int max_limit=0, const input_event_filter &evt_filter=allow_all_keys) const
Get a description text for the key/other input method associated with the given action.
Definition: input.cpp:756
void register_action(const std::string &action_descriptor)
Register an action with this input context.
Definition: input.cpp:676
void set_iso(bool mode=true)
Definition: input.cpp:1429
void reset_timeout()
Definition: input.cpp:1463
std::vector< cSCT > vSCT
Definition: output.h:947
void advanceAllSteps()
Definition: output.cpp:1924
bool has_timeout_elapsed()
input_context get_default_mode_input_context()
Definition: game.cpp:2410
static bool init_weather_anim(const weather_type_id &wtype, weather_printable &wPrint)
static void generate_weather_anim_frame(const weather_type_id &wtype, weather_printable &wPrint)
direction
Definition: line.h:39
scrollingcombattext SCT
Definition: output.cpp:65
Weather drawing tracking.
Definition: weather.h:59
translation to_translation(const std::string &raw)
Shorthands for translation::to_translation.

References _, action, ACTION_CENTER, action_ident(), ACTION_KEYBINDINGS, ACTION_LOOK, ACTION_SHIFT_E, ACTION_SHIFT_N, ACTION_SHIFT_NE, ACTION_SHIFT_NW, ACTION_SHIFT_S, ACTION_SHIFT_SE, ACTION_SHIFT_SW, ACTION_SHIFT_W, ACTION_TOGGLE_MAP_MEMORY, add_draw_callback(), scrollingcombattext::advanceAllSteps(), c_red, critter_at(), draw_sct(), draw_weather(), generate_weather_anim_frame(), get_default_mode_input_context(), input_context::get_desc(), get_levz(), get_weather, handle_mouseview(), user_turn::has_timeout_elapsed(), init_weather_anim(), invalidate_main_ui_adaptor(), m, minimap_requires_animation(), Character::posz(), QUIT_WATCH, ui_manager::redraw_invalidated(), input_context::register_action(), input_context::reset_timeout(), SCT, Character::sees(), input_context::set_iso(), input_context::set_timeout(), terrain_requires_animation(), to_translation(), u, map::update_visibility_cache(), uquit, utf8_width(), and scrollingcombattext::vSCT.

Referenced by handle_action().

◆ get_seed()

unsigned int game::get_seed ( ) const

Definition at line 1861 of file game.cpp.

1862{
1863 return seed;
1864}

References seed.

◆ get_user_action_counter()

int game::get_user_action_counter ( ) const

Definition at line 7360 of file game.cpp.

7361{
7362 return user_action_counter;
7363}

References user_action_counter.

◆ get_veh_dir_indicator_location()

cata::optional< tripoint > game::get_veh_dir_indicator_location ( bool  next) const

Returns the location where the indicator should go relative to the reality bubble, or nothing to indicate no indicator should be drawn.

Based on the vehicle the player is driving, if any.

Parameters
nextIf true, bases it on the vehicle the vehicle will turn to next turn, instead of the one it is currently facing.

Definition at line 3625 of file game.cpp.

3626{
3627 if( !get_option<bool>( "VEHICLE_DIR_INDICATOR" ) ) {
3628 return cata::nullopt;
3629 }
3630 const optional_vpart_position vp = m.veh_at( u.pos() );
3631 if( !vp ) {
3632 return cata::nullopt;
3633 }
3634 vehicle *const veh = &vp->vehicle();
3635 rl_vec2d face = next ? veh->dir_vec() : veh->face_vec();
3636 float r = 10.0;
3637 return tripoint( static_cast<int>( r * face.x ), static_cast<int>( r * face.y ), u.pos().z );
3638}
rl_vec2d dir_vec() const

References vehicle::dir_vec(), vehicle::face_vec(), m, cata::nullopt, Character::pos(), u, map::veh_at(), rl_vec2d::x, rl_vec2d::y, and tripoint::z.

Referenced by draw_veh_dir_indicator().

◆ get_world_base_save_path()

std::string game::get_world_base_save_path ( ) const

Base path for saving world data.

This yields a path to a folder.

Definition at line 12531 of file game.cpp.

12532{
12533 if( world_generator->active_world == nullptr ) {
12534 return PATH_INFO::savedir();
12535 }
12536 return world_generator->active_world->folder_path();
12537}
std::string savedir()
Definition: path_info.cpp:250

References PATH_INFO::savedir(), and world_generator.

Referenced by get_player_base_save_path(), load(), load_master(), move_save_to_graveyard(), save(), save_artifacts(), and save_factions_missions_npcs().

◆ get_zoom()

int game::get_zoom ( ) const

Definition at line 7346 of file game.cpp.

7347{
7348#if defined(TILES)
7349 return tileset_zoom;
7350#else
7351 return DEFAULT_TILESET_ZOOM;
7352#endif
7353}

References DEFAULT_TILESET_ZOOM, and tileset_zoom.

Referenced by look_around().

◆ grabbed_furn_move()

bool game::grabbed_furn_move ( const tripoint dp)
private
Strength determines ability to drag furniture

Definition at line 10065 of file game.cpp.

10066{
10067 // Furniture: pull, push, or standing still and nudging object around.
10068 // Can push furniture out of reach.
10069 tripoint fpos = u.pos() + u.grab_point;
10070 // supposed position of grabbed furniture
10071 if( !m.has_furn( fpos ) ) {
10072 // Where did it go? We're grabbing thin air so reset.
10073 add_msg( m_info, _( "No furniture at grabbed point." ) );
10074 u.grab( OBJECT_NONE );
10075 return false;
10076 }
10077
10078 const bool pushing_furniture = dp == u.grab_point;
10079 const bool pulling_furniture = dp == -u.grab_point;
10080 const bool shifting_furniture = !pushing_furniture && !pulling_furniture;
10081
10082 tripoint fdest = fpos + dp; // intended destination of furniture.
10083 // Check floor: floorless tiles don't need to be flat and have no traps
10084 const bool has_floor = m.has_floor( fdest );
10085 // Unfortunately, game::is_empty fails for tiles we're standing on,
10086 // which will forbid pulling, so:
10087 const bool canmove = (
10088 m.passable( fdest ) &&
10089 critter_at<npc>( fdest ) == nullptr &&
10090 critter_at<monster>( fdest ) == nullptr &&
10091 ( !pulling_furniture || is_empty( u.pos() + dp ) ) &&
10092 ( !has_floor || m.has_flag( "FLAT", fdest ) ) &&
10093 !m.has_furn( fdest ) &&
10094 !m.veh_at( fdest ) &&
10095 ( !has_floor || m.tr_at( fdest ).is_null() )
10096 );
10097
10098 const furn_t furntype = m.furn( fpos ).obj();
10099 const int src_items = m.i_at( fpos ).size();
10100 const int dst_items = m.i_at( fdest ).size();
10101
10102 const bool only_liquid_items = std::all_of( m.i_at( fdest ).begin(), m.i_at( fdest ).end(),
10103 [&]( item & liquid_item ) {
10104 return liquid_item.made_of( LIQUID );
10105 } );
10106
10107 const bool dst_item_ok = !m.has_flag( "NOITEM", fdest ) &&
10108 !m.has_flag( "SWIMMABLE", fdest ) &&
10109 !m.has_flag( "DESTROY_ITEM", fdest );
10110
10111 const bool src_item_ok = m.furn( fpos ).obj().has_flag( "CONTAINER" ) ||
10112 m.furn( fpos ).obj().has_flag( "FIRE_CONTAINER" ) ||
10113 m.furn( fpos ).obj().has_flag( "SEALED" );
10114
10115 const int fire_intensity = m.get_field_intensity( fpos, fd_fire );
10116 time_duration fire_age = m.get_field_age( fpos, fd_fire );
10117
10118 int str_req = furntype.move_str_req;
10119 // Factor in weight of items contained in the furniture.
10120 units::mass furniture_contents_weight = 0_gram;
10121 for( auto &contained_item : m.i_at( fpos ) ) {
10122 furniture_contents_weight += contained_item.weight();
10123 }
10124 str_req += furniture_contents_weight / 4_kilogram;
10125 if( !canmove ) {
10126 // TODO: What is something?
10127 add_msg( _( "The %s collides with something." ), furntype.name() );
10128 u.moves -= 50;
10129 return true;
10130 ///\EFFECT_STR determines ability to drag furniture
10131 } else if( str_req > u.get_str() &&
10132 one_in( std::max( 20 - str_req - u.get_str(), 2 ) ) ) {
10133 add_msg( m_bad, _( "You strain yourself trying to move the heavy %s!" ),
10134 furntype.name() );
10135 u.moves -= 100;
10136 u.mod_pain( 1 ); // Hurt ourselves.
10137 return true; // furniture and or obstacle wins.
10138 } else if( !src_item_ok && !only_liquid_items && dst_items > 0 ) {
10139 add_msg( _( "There's stuff in the way." ) );
10140 u.moves -= 50;
10141 return true;
10142 }
10143
10144 u.moves -= str_req * 10;
10145 // Additional penalty if we can't comfortably move it.
10146 if( str_req > u.get_str() ) {
10147 int move_penalty = std::pow( str_req, 2.0 ) + 100.0;
10148 if( move_penalty <= 1000 ) {
10149 if( u.get_str() >= str_req - 3 ) {
10150 u.moves -= std::max( 3000, move_penalty * 10 );
10151 add_msg( m_bad, _( "The %s is really heavy!" ), furntype.name() );
10152 if( one_in( 3 ) ) {
10153 add_msg( m_bad, _( "You fail to move the %s." ), furntype.name() );
10154 return true;
10155 }
10156 } else {
10157 u.moves -= 100;
10158 add_msg( m_bad, _( "The %s is too heavy for you to budge." ), furntype.name() );
10159 return true;
10160 }
10161 }
10162 u.moves -= move_penalty;
10163 if( move_penalty > 500 ) {
10164 add_msg( _( "Moving the heavy %s is taking a lot of time!" ),
10165 furntype.name() );
10166 } else if( move_penalty > 200 ) {
10167 if( one_in( 3 ) ) { // Nag only occasionally.
10168 add_msg( _( "It takes some time to move the heavy %s." ),
10169 furntype.name() );
10170 }
10171 }
10172 }
10174 _( "a scraping noise." ), true, "misc", "scraping" );
10175
10177 ( tripoint_abs_ms( m.getabs( fpos ) ) );
10178
10179 // Actually move the furniture.
10180 m.furn_set( fdest, m.furn( fpos ), atd ? atd->clone() : nullptr );
10181 m.furn_set( fpos, f_null );
10182
10183 if( fire_intensity == 1 && !pulling_furniture ) {
10184 m.remove_field( fpos, fd_fire );
10185 m.set_field_intensity( fdest, fd_fire, fire_intensity );
10186 m.set_field_age( fdest, fd_fire, fire_age );
10187 }
10188
10189 // Is there is only liquids on the ground, remove them after moving furniture.
10190 if( dst_items > 0 && only_liquid_items ) {
10191 m.i_clear( fdest );
10192 }
10193
10194 if( src_items > 0 ) { // Move the stuff inside.
10195 if( dst_item_ok && src_item_ok ) {
10196 // Assume contents of both cells are legal, so we can just swap contents.
10197 std::list<item> temp;
10198 std::move( m.i_at( fpos ).begin(), m.i_at( fpos ).end(),
10199 std::back_inserter( temp ) );
10200 m.i_clear( fpos );
10201 for( auto item_iter = m.i_at( fdest ).begin();
10202 item_iter != m.i_at( fdest ).end(); ++item_iter ) {
10203 m.i_at( fpos ).insert( *item_iter );
10204 }
10205 m.i_clear( fdest );
10206 for( auto &cur_item : temp ) {
10207 m.i_at( fdest ).insert( cur_item );
10208 }
10209 } else {
10210 add_msg( _( "Stuff spills from the %s!" ), furntype.name() );
10211 }
10212 }
10213
10214 if( shifting_furniture ) {
10215 // We didn't move
10216 tripoint d_sum = u.grab_point + dp;
10217 if( std::abs( d_sum.x ) < 2 && std::abs( d_sum.y ) < 2 ) {
10218 u.grab_point = d_sum; // furniture moved relative to us
10219 } else { // we pushed furniture out of reach
10220 add_msg( _( "You let go of the %s." ), furntype.name() );
10221 u.grab( OBJECT_NONE );
10222 }
10223 return true; // We moved furniture but stayed still.
10224 }
10225
10226 if( pushing_furniture && m.impassable( fpos ) ) {
10227 // Not sure how that chair got into a wall, but don't let player follow.
10228 add_msg( _( "You let go of the %1$s as it slides past %2$s." ),
10229 furntype.name(), m.tername( fdest ) );
10230 u.grab( OBJECT_NONE );
10231 return true;
10232 }
10233
10234 return false;
10235}
virtual int get_str() const
Getters for stats exclusive to characters.
Definition: character.cpp:3938
virtual active_tile_data * clone() const =0
void grab(object_type grab_type, const tripoint &grab_point=tripoint_zero)
Definition: avatar.cpp:639
bool is_empty(const tripoint &p)
Returns true if there is no player, NPC, or monster on the tile and move_cost > 0.
Definition: game.cpp:5137
void insert(const item &newitem) override
Definition: map.cpp:152
void remove_field(const tripoint &p, const field_type_id &field_to_remove)
Remove field entry at xy, ignored if the field entry is not present.
Definition: map.cpp:5457
time_duration set_field_age(const tripoint &p, const field_type_id &type, const time_duration &age, bool isoffset=false)
Set age of field entry at point.
Definition: map.cpp:5331
time_duration get_field_age(const tripoint &p, const field_type_id &type) const
Get the age of a field entry (field_entry::age), if there is no field of that type,...
Definition: map.cpp:5365
int get_field_intensity(const tripoint &p, const field_type_id &type) const
Get the intensity of a field entry (field_entry::intensity), if there is no field of that type,...
Definition: map.cpp:5371
int set_field_intensity(const tripoint &p, const field_type_id &type, int new_intensity, bool isoffset=false)
Set intensity of field entry at point, creating if not present, removing if intensity becomes 0.
Definition: map.cpp:5344
std::string tername(const tripoint &p) const
Definition: map.cpp:1720
void i_clear(const tripoint &p)
Definition: map.cpp:4115
void furn_set(const tripoint &p, const furn_id &new_furniture, cata::poly_serialized< active_tile_data > new_active=nullptr)
Sets the furniture at given position.
Definition: map.cpp:1371
bool has_floor(const tripoint &p) const
Definition: map.cpp:2018
tripoint grab_point
Definition: player.h:682
coords::coord_point< tripoint, coords::origin::abs, coords::ms > tripoint_abs_ms
Definition: coordinates.h:486
@ OBJECT_NONE
Definition: enums.h:187
field_type_id fd_fire
Definition: field_type.cpp:345
furn_id f_null
Definition: mapdata.cpp:1095
template active_tile_data * furn_at< active_tile_data >(const tripoint_abs_ms &)
bool move(avatar &you, map &m, const tripoint &d)
void sound(const tripoint &p, int vol, sound_t category, const std::string &description, bool ambient=false, const std::string &id="", const std::string &variant="default")
Sound at (p) of intensity (vol)
Definition: sounds.cpp:177
int move_str_req
Definition: mapdata.h:505
bool has_flag(const std::string &flag) const
Definition: mapdata.h:415

References _, add_msg(), item_stack::begin(), active_tile_data::clone(), item_stack::end(), f_null, fd_fire, map::furn(), active_tiles::furn_at< active_tile_data >(), map::furn_set(), map::get_field_age(), map::get_field_intensity(), Character::get_str(), map::getabs(), avatar::grab(), player::grab_point, map_data_common_t::has_flag(), map::has_flag(), map::has_floor(), map::has_furn(), map::i_at(), map::i_clear(), map::impassable(), map_stack::insert(), is_empty(), trap::is_null(), m, m_bad, m_info, player::mod_pain(), avatar_action::move(), furn_t::move_str_req, sounds::movement, Creature::moves, map_data_common_t::name(), int_id< T >::obj(), OBJECT_NONE, one_in(), map::passable(), Character::pos(), map::remove_field(), map::set_field_age(), map::set_field_intensity(), item_stack::size(), sounds::sound(), map::tername(), map::tr_at(), u, map::veh_at(), tripoint::x, and tripoint::y.

Referenced by grabbed_move().

◆ grabbed_move()

bool game::grabbed_move ( const tripoint dp)
private

Check for dangerous stuff at dest_loc, return false if the player decides not to step there.

Definition at line 10237 of file game.cpp.

10238{
10239 if( u.get_grab_type() == OBJECT_NONE ) {
10240 return false;
10241 }
10242
10243 if( dp.z != 0 ) {
10244 // No dragging stuff up/down stairs yet!
10245 return false;
10246 }
10247
10248 // vehicle: pulling, pushing, or moving around the grabbed object.
10249 if( u.get_grab_type() == OBJECT_VEHICLE ) {
10250 return grabbed_veh_move( dp );
10251 }
10252
10253 if( u.get_grab_type() == OBJECT_FURNITURE ) {
10254 return grabbed_furn_move( dp );
10255 }
10256
10257 add_msg( m_info, _( "Nothing at grabbed point %d,%d,%d or bad grabbed object type." ),
10259 u.grab( OBJECT_NONE );
10260 return false;
10261}
object_type get_grab_type() const
Definition: avatar.cpp:647
bool grabbed_furn_move(const tripoint &dp)
Definition: game.cpp:10065
bool grabbed_veh_move(const tripoint &dp)
Definition: grab.cpp:21
@ OBJECT_FURNITURE
Definition: enums.h:197
@ OBJECT_VEHICLE
Definition: enums.h:193

References _, add_msg(), avatar::get_grab_type(), avatar::grab(), player::grab_point, grabbed_furn_move(), grabbed_veh_move(), m_info, OBJECT_FURNITURE, OBJECT_NONE, OBJECT_VEHICLE, u, tripoint::x, tripoint::y, and tripoint::z.

Referenced by walk_move().

◆ grabbed_veh_move()

bool game::grabbed_veh_move ( const tripoint dp)
private
Strength determines ability to drag vehicles Strength increases speed of dragging vehicles

Definition at line 21 of file grab.cpp.

22{
23 const optional_vpart_position grabbed_vehicle_vp = m.veh_at( u.pos() + u.grab_point );
24 if( !grabbed_vehicle_vp ) {
25 add_msg( m_info, _( "No vehicle at grabbed point." ) );
27 return false;
28 }
29 vehicle *grabbed_vehicle = &grabbed_vehicle_vp->vehicle();
30 if( !grabbed_vehicle ||
31 !grabbed_vehicle->handle_potential_theft( dynamic_cast<player &>( g->u ) ) ) {
32 return false;
33 }
34 const int grabbed_part = grabbed_vehicle_vp->part_index();
35 for( int part_index = 0; part_index < grabbed_vehicle->part_count(); ++part_index ) {
36 monster *mon = grabbed_vehicle->get_pet( part_index );
37 if( mon != nullptr && mon->has_effect( effect_harnessed ) ) {
38 add_msg( m_info, _( "You cannot move this vehicle whilst your %s is harnessed!" ),
39 mon->get_name() );
41 return false;
42 }
43 }
44 const vehicle *veh_under_player = veh_pointer_or_null( m.veh_at( u.pos() ) );
45 if( grabbed_vehicle == veh_under_player ) {
46 u.grab_point = -dp;
47 return false;
48 }
49
50 tripoint dp_veh = -u.grab_point;
51 const tripoint prev_grab = u.grab_point;
52 tripoint next_grab = u.grab_point;
53
54 bool zigzag = false;
55
56 if( dp == prev_grab ) {
57 // We are pushing in the direction of vehicle
58 dp_veh = dp;
59 } else if( std::abs( dp.x + dp_veh.x ) != 2 && std::abs( dp.y + dp_veh.y ) != 2 ) {
60 // Not actually moving the vehicle, don't do the checks
61 u.grab_point = -( dp + dp_veh );
62 return false;
63 } else if( ( dp.x == prev_grab.x || dp.y == prev_grab.y ) &&
64 next_grab.x != 0 && next_grab.y != 0 ) {
65 // Zig-zag (or semi-zig-zag) pull: player is diagonal to vehicle
66 // and moves away from it, but not directly away
67 dp_veh.x = dp.x == -dp_veh.x ? 0 : dp_veh.x;
68 dp_veh.y = dp.y == -dp_veh.y ? 0 : dp_veh.y;
69
70 next_grab = -dp_veh;
71 zigzag = true;
72 } else {
73 // We are pulling the vehicle
74 next_grab = -dp;
75 }
76
77 // Make sure the mass and pivot point are correct
78 grabbed_vehicle->invalidate_mass();
79
80 //vehicle movement: strength check
81 int mc = 0;
82 int str_req = grabbed_vehicle->total_mass() / 25_kilogram; //strength required to move vehicle.
83
84 //if vehicle is rollable we modify str_req based on a function of movecost per wheel.
85
86 // Vehicle just too big to grab & move; 41-45 lets folks have a bit of a window
87 // (Roughly 1.1K kg = danger zone; cube vans are about the max)
88 if( str_req > 45 ) {
89 add_msg( m_info, _( "The %s is too bulky for you to move by hand." ),
90 grabbed_vehicle->name );
91 return true; // No shoving around an RV.
92 }
93
94 const auto &wheel_indices = grabbed_vehicle->wheelcache;
95 if( grabbed_vehicle->valid_wheel_config() ) {
96 //determine movecost for terrain touching wheels
97 const tripoint vehpos = grabbed_vehicle->global_pos3();
98 for( int p : wheel_indices ) {
99 const tripoint wheel_pos = vehpos + grabbed_vehicle->part( p ).precalc[0];
100 const int mapcost = m.move_cost( wheel_pos, grabbed_vehicle );
101 mc += str_req / wheel_indices.size() * mapcost;
102 }
103 //set strength check threshold
104 //if vehicle has many or only one wheel (shopping cart), it is as if it had four.
105 if( wheel_indices.size() > 4 || wheel_indices.size() == 1 ) {
106 str_req = mc / 4 + 1;
107 } else {
108 str_req = mc / wheel_indices.size() + 1;
109 }
110 } else {
111 str_req++;
112 //if vehicle has no wheels str_req make a noise.
113 if( str_req <= u.get_str() ) {
114 sounds::sound( grabbed_vehicle->global_pos3(), str_req * 2, sounds::sound_t::movement,
115 _( "a scraping noise." ), true, "misc", "scraping" );
116 }
117 }
118
119 //final strength check and outcomes
120 ///\EFFECT_STR determines ability to drag vehicles
121 if( str_req <= u.get_str() ) {
122 //calculate exertion factor and movement penalty
123 ///\EFFECT_STR increases speed of dragging vehicles
124 u.moves -= 100 * str_req / std::max( 1, u.get_str() );
125 const int ex = dice( 1, 3 ) - 1 + str_req;
126 if( ex > u.get_str() + 1 ) {
127 // Pain and movement penalty if exertion exceeds character strength
128 add_msg( m_bad, _( "You strain yourself to move the %s!" ), grabbed_vehicle->name );
129 u.moves -= 200;
130 u.mod_pain( 1 );
131 } else if( ex >= u.get_str() ) {
132 // Movement is slow if exertion nearly equals character strength
133 add_msg( _( "It takes some time to move the %s." ), grabbed_vehicle->name );
134 u.moves -= 200;
135 }
136 } else {
137 u.moves -= 100;
138 add_msg( m_bad, _( "You lack the strength to move the %s" ), grabbed_vehicle->name );
139 return true;
140 }
141
142 std::string blocker_name = _( "errors in movement code" );
143 const auto get_move_dir = [&]( const tripoint & dir, const tripoint & from ) {
144 tileray mdir;
145
146 mdir.init( dir.xy() );
147 grabbed_vehicle->turn( mdir.dir() - grabbed_vehicle->face.dir() );
148 grabbed_vehicle->face = grabbed_vehicle->turn_dir;
149 grabbed_vehicle->precalc_mounts( 1, mdir.dir(), grabbed_vehicle->pivot_point() );
150
151 // Grabbed part has to stay at distance 1 to the player
152 // and in roughly the same direction.
153 const tripoint new_part_pos = grabbed_vehicle->global_pos3() +
154 grabbed_vehicle->part( grabbed_part ).precalc[ 1 ];
155 const tripoint expected_pos = u.pos() + dp + from;
156 const tripoint actual_dir = expected_pos - new_part_pos;
157
158 // Set player location to illegal value so it can't collide with vehicle.
159 const tripoint player_prev = u.pos();
161 std::vector<veh_collision> colls;
162 const bool failed = grabbed_vehicle->collision( colls, actual_dir, true );
163 u.setpos( player_prev );
164 if( !colls.empty() ) {
165 blocker_name = colls.front().target_name;
166 }
167 return failed ? tripoint_zero : actual_dir;
168 };
169
170 // First try the move as intended
171 // But if that fails and the move is a zig-zag, try to recover:
172 // Try to place the vehicle in the position player just left rather than "flattening" the zig-zag
173 tripoint final_dp_veh = get_move_dir( dp_veh, next_grab );
174 if( final_dp_veh == tripoint_zero && zigzag ) {
175 final_dp_veh = get_move_dir( -prev_grab, -dp );
176 next_grab = -dp;
177 }
178
179 if( final_dp_veh == tripoint_zero ) {
180 add_msg( _( "The %s collides with %s." ), grabbed_vehicle->name, blocker_name );
181 u.grab_point = prev_grab;
182 return true;
183 }
184
185 u.grab_point = next_grab;
186
187 m.displace_vehicle( *grabbed_vehicle, final_dp_veh );
188
189 if( grabbed_vehicle ) {
190 m.level_vehicle( *grabbed_vehicle );
191 grabbed_vehicle->check_falling_or_floating();
192 } else {
193 debugmsg( "Grabbed vehicle disappeared" );
194 return false;
195 }
196
197 for( int p : wheel_indices ) {
198 if( one_in( 2 ) ) {
199 tripoint wheel_p = grabbed_vehicle->global_part_pos3( grabbed_part );
200 grabbed_vehicle->handle_trap( wheel_p, p );
201 }
202 }
203
204 return false;
205
206}
int move_cost(const tripoint &p, const vehicle *ignored_vehicle=nullptr) const
Calculate the cost to move past the tile at p.
Definition: map.cpp:1791
bool displace_vehicle(vehicle &veh, const tripoint &dp, bool adjust_pos=true, const std::set< int > &parts_to_move={})
Definition: map.cpp:1098
void level_vehicle(vehicle &veh)
Definition: map.cpp:1282
units::angle dir() const
Definition: tileray.cpp:74
void init(const point &ad)
Definition: tileray.cpp:27
void turn(units::angle deg)
const point & pivot_point() const
Definition: vehicle.cpp:5636
tripoint global_pos3() const
Definition: vehicle.cpp:3101
void precalc_mounts(int idir, units::angle dir, const point &pivot)
Definition: vehicle.cpp:3024
bool valid_wheel_config() const
Definition: vehicle.cpp:4279
units::mass total_mass() const
Definition: vehicle.cpp:3126
std::vector< int > wheelcache
Definition: vehicle.h:1761
void check_falling_or_floating()
tileray face
Definition: vehicle.h:1891
void invalidate_mass()
Mark mass caches and pivot cache as dirty.
Definition: vehicle.cpp:6778
int part_count() const
Definition: vehicle.cpp:6887
bool collision(std::vector< veh_collision > &colls, const tripoint &dp, bool just_detect, bool bash_floor=false)
monster * get_pet(int p) const
Definition: vehicle.cpp:3082
vehicle_part & part(int part_num)
Definition: vehicle.cpp:6892
void handle_trap(const tripoint &p, int part)
tripoint global_part_pos3(const int &index) const
Get the coordinates of the studied part of the vehicle.
Definition: vehicle.cpp:3106
units::angle turn_dir
Definition: vehicle.h:1870
static const efftype_id effect_harnessed("harnessed")
static constexpr tripoint tripoint_zero
Definition: point.h:273
int dice(int number, int sides)
Definition: rng.cpp:85
std::array< tripoint, 2 > precalc
mount translated to face.dir [0] and turn_dir [1]
Definition: vehicle.h:371

References _, add_msg(), vehicle::check_falling_or_floating(), vehicle::collision(), debugmsg, dice(), tileray::dir(), map::displace_vehicle(), effect_harnessed, vehicle::face, failed, g, monster::get_name(), vehicle::get_pet(), Character::get_str(), vehicle::global_part_pos3(), vehicle::global_pos3(), avatar::grab(), player::grab_point, vehicle::handle_potential_theft(), vehicle::handle_trap(), Creature::has_effect(), tileray::init(), vehicle::invalidate_mass(), map::level_vehicle(), m, m_bad, m_info, player::mod_pain(), map::move_cost(), sounds::movement, Creature::moves, vehicle::name, OBJECT_NONE, one_in(), vehicle::part(), vehicle::part_count(), vehicle::pivot_point(), Character::pos(), vehicle_part::precalc, vehicle::precalc_mounts(), Character::setpos(), sounds::sound(), vehicle::total_mass(), tripoint_zero, vehicle::turn(), vehicle::turn_dir, u, vehicle::valid_wheel_config(), map::veh_at(), veh_pointer_or_null(), vehicle::wheelcache, tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by grabbed_move().

◆ handle_action()

bool game::handle_action ( )
private

Definition at line 1516 of file handle_action.cpp.

1517{
1518 std::string action;
1519 input_context ctxt;
1521 user_turn current_turn;
1522 // Check if we have an auto-move destination
1523 if( u.has_destination() ) {
1525 if( act == ACTION_NULL ) {
1526 add_msg( m_info, _( "Auto-move canceled" ) );
1528 return false;
1529 }
1530 } else if( u.has_destination_activity() ) {
1531 // starts destination activity after the player successfully reached his destination
1533 return false;
1534 } else {
1535 // No auto-move, ask player for input
1536 ctxt = get_player_input( action );
1537 }
1538
1539 const optional_vpart_position vp = m.veh_at( u.pos() );
1540 bool veh_ctrl = !u.is_dead_state() &&
1541 ( ( vp && vp->vehicle().player_in_control( u ) ) || remoteveh() != nullptr );
1542
1543 // If performing an action with right mouse button, co-ordinates
1544 // of location clicked.
1545 cata::optional<tripoint> mouse_target;
1546
1547 if( uquit == QUIT_WATCH && action == "QUIT" ) {
1548 uquit = QUIT_DIED;
1549 return false;
1550 }
1551
1552 if( act == ACTION_NULL ) {
1554
1555 if( act == ACTION_KEYBINDINGS ) {
1556 // already handled by input context
1557 return false;
1558 }
1559
1560 if( act == ACTION_MAIN_MENU ) {
1561 if( uquit == QUIT_WATCH ) {
1562 return false;
1563 }
1564 // No auto-move actions have or can be set at this point.
1566 destination_preview.clear();
1568 if( act == ACTION_NULL ) {
1569 return false;
1570 }
1571 }
1572
1573 if( act == ACTION_ACTIONMENU ) {
1574 if( uquit == QUIT_WATCH ) {
1575 return false;
1576 }
1577 // No auto-move actions have or can be set at this point.
1579 destination_preview.clear();
1581 if( act == ACTION_NULL ) {
1582 return false;
1583 }
1584#if defined(__ANDROID__)
1585 if( get_option<bool>( "ANDROID_ACTIONMENU_AUTOADD" ) && ctxt.get_category() == "DEFAULTMODE" ) {
1586 add_best_key_for_action_to_quick_shortcuts( act, ctxt.get_category(), false );
1587 }
1588#endif
1589 }
1590
1591 if( act == ACTION_KEYBINDINGS ) {
1593 destination_preview.clear();
1594 act = ctxt.display_menu( true );
1595 if( act == ACTION_NULL ) {
1596 return false;
1597 }
1598 }
1599
1602 }
1603
1604 if( act == ACTION_SELECT || act == ACTION_SEC_SELECT ) {
1605 // Mouse button click
1606 if( veh_ctrl ) {
1607 // No mouse use in vehicle
1608 return false;
1609 }
1610
1611 if( u.is_dead_state() ) {
1612 // do not allow mouse actions while dead
1613 return false;
1614 }
1615
1616 const cata::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
1617 if( !mouse_pos ) {
1618 return false;
1619 } else if( !u.sees( *mouse_pos ) ) {
1620 // Not clicked in visible terrain
1621 return false;
1622 }
1623 mouse_target = mouse_pos;
1624
1625 if( act == ACTION_SELECT ) {
1626 // Note: The following has the potential side effect of
1627 // setting auto-move destination state in addition to setting
1628 // act.
1629 if( !try_get_left_click_action( act, *mouse_target ) ) {
1630 return false;
1631 }
1632 } else if( act == ACTION_SEC_SELECT ) {
1633 if( !try_get_right_click_action( act, *mouse_target ) ) {
1634 return false;
1635 }
1636 }
1637 } else if( act != ACTION_TIMEOUT ) {
1638 // act has not been set for an auto-move, so clearing possible
1639 // auto-move destinations. Since initializing an auto-move with
1640 // the mouse may span across multiple actions, we do not clear the
1641 // auto-move destination if the action is only a timeout, as this
1642 // would require the user to double click quicker than the
1643 // timeout delay.
1645 destination_preview.clear();
1646 }
1647 }
1648
1649 if( act == ACTION_NULL ) {
1650 const input_event &&evt = ctxt.get_raw_input();
1651 if( !evt.sequence.empty() ) {
1652 const int ch = evt.get_first_input();
1653 const std::string &&name = inp_mngr.get_keyname( ch, evt.type, true );
1654 if( !get_option<bool>( "NO_UNKNOWN_COMMAND_MSG" ) ) {
1655 add_msg( m_info, _( "Unknown command: \"%s\" (%ld)" ), name, ch );
1656 if( const cata::optional<std::string> hint =
1658 add_msg( m_info, _( "%s at any time to see and edit keybindings relevant to "
1659 "the current context." ),
1660 *hint );
1661 }
1662 }
1663 }
1664 return false;
1665 }
1666
1667 // This has no action unless we're in a special game mode.
1668 gamemode->pre_action( act );
1669
1670 int soffset = get_option<int>( "MOVE_VIEW_OFFSET" );
1671
1672 int before_action_moves = u.moves;
1673
1674 // These actions are allowed while deathcam is active. Registered in game::get_player_input
1675 if( uquit == QUIT_WATCH || !u.is_dead_state() ) {
1676 switch( act ) {
1679 break;
1680
1681 case ACTION_CENTER:
1684 break;
1685
1686 case ACTION_SHIFT_N:
1687 case ACTION_SHIFT_NE:
1688 case ACTION_SHIFT_E:
1689 case ACTION_SHIFT_SE:
1690 case ACTION_SHIFT_S:
1691 case ACTION_SHIFT_SW:
1692 case ACTION_SHIFT_W:
1693 case ACTION_SHIFT_NW: {
1694 static const std::map<action_id, std::pair<point, point>> shift_delta = {
1703 };
1705 shift_delta.at( act ).second * soffset : shift_delta.at( act ).first * soffset;
1706 }
1707 break;
1708
1709 case ACTION_LOOK:
1710 look_around();
1711 break;
1712
1713 case ACTION_KEYBINDINGS:
1714 // already handled by input context
1715 break;
1716
1717 default:
1718 break;
1719 }
1720 }
1721
1722 // actions allowed only while alive
1723 if( !u.is_dead_state() ) {
1724 switch( act ) {
1725 case ACTION_NULL:
1726 case NUM_ACTIONS:
1727 break; // dummy entries
1728 case ACTION_ACTIONMENU:
1729 case ACTION_MAIN_MENU:
1730 case ACTION_KEYBINDINGS:
1731 break; // handled above
1732
1733 case ACTION_TIMEOUT:
1734 if( check_safe_mode_allowed( false ) ) {
1735 u.pause();
1736 }
1737 break;
1738
1739 case ACTION_PAUSE:
1740 if( check_safe_mode_allowed() ) {
1741 u.pause();
1742 }
1743 break;
1744
1745 case ACTION_CYCLE_MOVE:
1747 break;
1748
1749 case ACTION_RESET_MOVE:
1751 break;
1752
1753 case ACTION_TOGGLE_RUN:
1755 break;
1756
1759 break;
1760
1763 break;
1764
1765 case ACTION_MOVE_FORTH:
1767 case ACTION_MOVE_RIGHT:
1769 case ACTION_MOVE_BACK:
1771 case ACTION_MOVE_LEFT:
1773 if( !u.get_value( "remote_controlling" ).empty() &&
1777 } else if( veh_ctrl ) {
1778 // vehicle control uses x for steering and y for ac/deceleration,
1779 // so no rotation needed
1781 } else {
1783 if( auto_travel_mode && !u.is_auto_moving() ) {
1784 for( int i = 0; i < SEEX; i++ ) {
1785 tripoint auto_travel_destination( u.posx() + dest_delta.x * ( SEEX - i ),
1786 u.posy() + dest_delta.y * ( SEEX - i ),
1787 u.posz() );
1789 auto_travel_destination,
1791 u.get_path_avoid() );
1792 if( !destination_preview.empty() ) {
1795 break;
1796 }
1797 }
1800 if( dest_next == point_zero ) {
1802 }
1803 dest_delta = dest_next;
1804 }
1805 if( !avatar_action::move( u, m, dest_delta ) ) {
1806 // auto-move should be canceled due to a failed move or obstacle
1808 }
1809 }
1810 break;
1811 case ACTION_MOVE_DOWN:
1812 if( u.is_mounted() ) {
1813 auto mon = u.mounted_creature.get();
1814 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1815 add_msg( m_info, _( "You can't go down stairs while you're riding." ) );
1816 break;
1817 }
1818 }
1819 if( !u.in_vehicle ) {
1820 vertical_move( -1, false );
1821 } else if( veh_ctrl && vp->vehicle().is_rotorcraft() ) {
1823 }
1824 break;
1825
1826 case ACTION_MOVE_UP:
1827 if( u.is_mounted() ) {
1828 auto mon = u.mounted_creature.get();
1829 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1830 add_msg( m_info, _( "You can't go down stairs while you're riding." ) );
1831 break;
1832 }
1833 }
1834 if( !u.in_vehicle ) {
1835 vertical_move( 1, false );
1836 } else if( veh_ctrl && vp->vehicle().is_rotorcraft() ) {
1838 } else if( veh_ctrl && vp->vehicle().has_part( "ROTOR" ) &&
1839 !vp->vehicle().has_sufficient_rotorlift() ) {
1840 add_msg( m_bad, _( "The rotors struggle to generate enough lift!" ) );
1841 }
1842 break;
1843
1844 case ACTION_OPEN:
1846 add_msg( m_info, _( "You can't open things while you're in your shell." ) );
1847 } else if( u.is_mounted() ) {
1848 add_msg( m_info, _( "You can't open things while you're riding." ) );
1849 } else {
1850 open();
1851 }
1852 break;
1853
1854 case ACTION_CLOSE:
1856 add_msg( m_info, _( "You can't close things while you're in your shell." ) );
1857 } else if( u.is_mounted() ) {
1858 auto mon = u.mounted_creature.get();
1859 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1860 add_msg( m_info, _( "You can't close things while you're riding." ) );
1861 }
1862 } else if( mouse_target ) {
1863 doors::close_door( m, u, *mouse_target );
1864 } else {
1865 close();
1866 }
1867 break;
1868
1869 case ACTION_SMASH:
1870 if( veh_ctrl ) {
1871 handbrake();
1872 } else if( u.has_active_mutation( trait_SHELL2 ) ) {
1873 add_msg( m_info, _( "You can't smash things while you're in your shell." ) );
1874 } else {
1875 smash();
1876 }
1877 break;
1878
1879 case ACTION_EXAMINE:
1881 add_msg( m_info, _( "You can't examine your surroundings while you're in your shell." ) );
1882 } else if( mouse_target ) {
1883 examine( *mouse_target );
1884 } else {
1885 examine();
1886 }
1887 break;
1888
1889 case ACTION_ADVANCEDINV:
1891 add_msg( m_info, _( "You can't move mass quantities while you're in your shell." ) );
1892 } else if( u.is_mounted() ) {
1893 add_msg( m_info, _( "You can't move mass quantities while you're riding." ) );
1894 } else {
1896 }
1897 break;
1898
1899 case ACTION_PICKUP:
1901 add_msg( m_info, _( "You can't pick anything up while you're in your shell." ) );
1902 } else if( u.is_mounted() ) {
1903 add_msg( m_info, _( "You can't pick anything up while you're riding." ) );
1904 } else if( mouse_target ) {
1905 pickup( *mouse_target );
1906 } else {
1907 pickup();
1908 }
1909 break;
1910
1911 case ACTION_PICKUP_FEET:
1913 add_msg( m_info, _( "You can't pick anything up while you're in your shell." ) );
1914 } else {
1915 pickup_feet();
1916 }
1917 break;
1918
1919 case ACTION_GRAB:
1921 add_msg( m_info, _( "You can't grab things while you're in your shell." ) );
1922 } else if( u.is_mounted() ) {
1923 add_msg( m_info, _( "You can't grab things while you're riding." ) );
1924 } else {
1925 grab();
1926 }
1927 break;
1928
1929 case ACTION_HAUL:
1931 add_msg( m_info, _( "You can't haul things while you're in your shell." ) );
1932 } else if( u.is_mounted() ) {
1933 add_msg( m_info, _( "You can't haul things while you're riding." ) );
1934 } else {
1935 haul();
1936 }
1937 break;
1938
1939 case ACTION_BUTCHER:
1941 add_msg( m_info, _( "You can't butcher while you're in your shell." ) );
1942 } else if( u.is_mounted() ) {
1943 add_msg( m_info, _( "You can't butcher while you're riding." ) );
1944 } else {
1945 butcher();
1946 }
1947 break;
1948
1949 case ACTION_CHAT:
1950 chat();
1951 break;
1952
1953 case ACTION_PEEK:
1955 add_msg( m_info, _( "You can't peek around corners while you're in your shell." ) );
1956 } else if( u.is_mounted() ) {
1957 add_msg( m_info, _( "You can't peek around corners while you're riding." ) );
1958 } else {
1959 peek();
1960 }
1961 break;
1962
1963 case ACTION_LIST_ITEMS:
1965 break;
1966
1967 case ACTION_ZONES:
1968 zones_manager();
1969 break;
1970
1971 case ACTION_LOOT:
1972 loot();
1973 break;
1974
1975 case ACTION_INVENTORY:
1977 break;
1978
1979 case ACTION_COMPARE:
1981 break;
1982
1983 case ACTION_ORGANIZE:
1985 break;
1986
1987 case ACTION_USE:
1988 // Shell-users are presumed to be able to mess with their inventories, etc
1989 // while in the shell. Eating, gear-changing, and item use are OK.
1991 break;
1992
1993 case ACTION_USE_WIELDED:
1994 u.use_wielded();
1995 break;
1996
1997 case ACTION_WEAR:
1998 wear();
1999 break;
2000
2001 case ACTION_TAKE_OFF:
2002 takeoff();
2003 break;
2004
2005 case ACTION_EAT:
2006 if( !avatar_action::eat_here( u ) ) {
2008 }
2009 break;
2010
2012 if( !avatar_action::eat_here( u ) ) {
2014 }
2015 break;
2016
2017 case ACTION_READ:
2018 // Shell-users are presumed to have the book just at an opening and read it that way
2019 read();
2020 break;
2021
2022 case ACTION_WIELD:
2023 wield();
2024 break;
2025
2026 case ACTION_PICK_STYLE:
2027 u.martial_arts_data->pick_style( u );
2028 break;
2029
2030 case ACTION_RELOAD_ITEM:
2031 reload_item();
2032 break;
2033
2035 reload_weapon();
2036 break;
2037
2040 break;
2041
2042 case ACTION_UNLOAD:
2044 break;
2045
2046 case ACTION_MEND:
2048 break;
2049
2050 case ACTION_THROW: {
2051 item_location loc;
2052 avatar_action::plthrow( g->u, loc );
2053 break;
2054 }
2055
2056 case ACTION_FIRE:
2057 fire();
2058 break;
2059
2060 case ACTION_CAST_SPELL:
2061 cast_spell();
2062 break;
2063
2064 case ACTION_FIRE_BURST: {
2065 if( u.weapon.gun_set_mode( gun_mode_id( "AUTO" ) ) ) {
2067 }
2068 break;
2069 }
2070
2072 if( u.is_armed() ) {
2073 if( u.weapon.is_gun() && !u.weapon.is_gunmod() && u.weapon.gun_all_modes().size() > 1 ) {
2076 item::reload_option opt = u.select_ammo( u.weapon, false );
2077 if( !opt ) {
2078 break;
2079 } else if( u.ammo_location && opt.ammo == u.ammo_location ) {
2081 } else {
2082 u.ammo_location = opt.ammo;
2083 }
2084 }
2085 }
2086 break;
2087
2088 case ACTION_DROP:
2089 // You CAN drop things to your own tile while in the shell.
2090 drop();
2091 break;
2092
2093 case ACTION_DIR_DROP:
2095 add_msg( m_info, _( "You can't drop things to another tile while you're in your shell." ) );
2096 } else {
2098 }
2099 break;
2100 case ACTION_BIONICS:
2101 u.power_bionics();
2102 break;
2103 case ACTION_MUTATIONS:
2105 break;
2106
2107 case ACTION_SORT_ARMOR:
2108 u.sort_armor();
2109 break;
2110
2111 case ACTION_WAIT:
2112 wait();
2113 break;
2114
2115 case ACTION_CRAFT:
2117 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2118 } else if( u.is_mounted() ) {
2119 add_msg( m_info, _( "You can't craft while you're riding." ) );
2120 } else {
2121 u.craft();
2122 }
2123 break;
2124
2125 case ACTION_RECRAFT:
2127 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2128 } else if( u.is_mounted() ) {
2129 add_msg( m_info, _( "You can't craft while you're riding." ) );
2130 } else {
2131 u.recraft();
2132 }
2133 break;
2134
2135 case ACTION_LONGCRAFT:
2137 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2138 } else if( u.is_mounted() ) {
2139 add_msg( m_info, _( "You can't craft while you're riding." ) );
2140 } else {
2141 u.long_craft();
2142 }
2143 break;
2144
2145 case ACTION_DISASSEMBLE:
2146 if( u.controlling_vehicle ) {
2147 add_msg( m_info, _( "You can't disassemble items while driving." ) );
2148 } else if( u.is_mounted() ) {
2149 add_msg( m_info, _( "You can't disassemble items while you're riding." ) );
2150 } else {
2151 u.disassemble();
2152 }
2153 break;
2154
2155 case ACTION_CONSTRUCT:
2156 if( u.in_vehicle ) {
2157 add_msg( m_info, _( "You can't construct while in a vehicle." ) );
2158 } else if( u.has_active_mutation( trait_SHELL2 ) ) {
2159 add_msg( m_info, _( "You can't construct while you're in your shell." ) );
2160 } else if( u.is_mounted() ) {
2161 add_msg( m_info, _( "You can't construct while you're riding." ) );
2162 } else {
2163 construction_menu( false );
2164 }
2165 break;
2166
2167 case ACTION_SLEEP:
2168 if( veh_ctrl ) {
2169 add_msg( m_info, _( "Vehicle control has moved, %s" ),
2170 press_x( ACTION_CONTROL_VEHICLE, _( "new binding is " ),
2171 _( "new default binding is '^'." ) ) );
2172 } else {
2173 sleep();
2174 }
2175 break;
2176
2179 add_msg( m_info, _( "You can't operate a vehicle while you're in your shell." ) );
2180 } else if( u.is_mounted() ) {
2181 u.dismount();
2182 } else {
2184 }
2185 break;
2186
2189 add_msg( m_info, auto_travel_mode ? _( "Auto travel mode ON!" ) : _( "Auto travel mode OFF!" ) );
2190 break;
2191
2193 if( safe_mode == SAFE_MODE_OFF ) {
2195 mostseen = 0;
2196 add_msg( m_info, _( "Safe mode ON!" ) );
2197 } else {
2200 add_msg( m_info, get_option<bool>( "AUTOSAFEMODE" )
2201 ? _( "Safe mode OFF! (Auto safe mode still enabled!)" ) : _( "Safe mode OFF!" ) );
2202 }
2206 }
2207 break;
2208
2210 auto &autosafemode_option = get_options().get_option( "AUTOSAFEMODE" );
2211 add_msg( m_info, autosafemode_option.value_as<bool>()
2212 ? _( "Auto safe mode OFF!" ) : _( "Auto safe mode ON!" ) );
2213 autosafemode_option.setNext();
2214 break;
2215 }
2216
2218 if( safe_mode == SAFE_MODE_STOP ) {
2219 add_msg( m_info, _( "Ignoring enemy!" ) );
2220 for( auto &elem : u.get_mon_visible().new_seen_mon ) {
2221 monster &critter = *elem;
2222 critter.ignoring = rl_dist( u.pos(), critter.pos() );
2223 }
2225 } else if( u.has_effect( effect_laserlocked ) ) {
2226 if( u.has_trait( trait_PROF_CHURL ) ) {
2227 add_msg( m_warning, _( "You make the sign of the cross." ) );
2228 } else {
2229 add_msg( m_info, _( "Ignoring laser targeting!" ) );
2230 }
2233 }
2234 break;
2235
2237 if( safe_mode == SAFE_MODE_STOP && !get_safemode().empty() ) {
2239 add_msg( m_info, _( "Creature whitelisted: %s" ), get_safemode().lastmon_whitelist );
2241 mostseen = 0;
2242 } else {
2243 get_safemode().show();
2244 }
2245 break;
2246
2247 case ACTION_SUICIDE:
2248 if( query_yn( _( "Commit suicide?" ) ) ) {
2249 if( query_yn( _( "REALLY commit suicide?" ) ) ) {
2250 u.moves = 0;
2251 u.place_corpse();
2253 }
2254 }
2255 break;
2256
2257 case ACTION_SAVE:
2258 if( query_yn( _( "Save and quit?" ) ) ) {
2259 if( save() ) {
2260 u.moves = 0;
2261 uquit = QUIT_SAVED;
2262 }
2263 }
2264 break;
2265
2266 case ACTION_QUICKSAVE:
2267 quicksave();
2268 return false;
2269
2270 case ACTION_QUICKLOAD:
2271 quickload();
2272 return false;
2273
2274 case ACTION_PL_INFO:
2275 u.disp_info();
2276 break;
2277
2278 case ACTION_MAP:
2280 break;
2281
2282 case ACTION_SKY:
2283 if( m.is_outside( u.pos() ) ) {
2285 } else {
2286 add_msg( m_info, _( "You can't see the sky from here." ) );
2287 }
2288 break;
2289
2290 case ACTION_MISSIONS:
2291 list_missions();
2292 break;
2293
2294 case ACTION_SCORES:
2296 break;
2297
2298 case ACTION_FACTIONS:
2299 faction_manager_ptr->display();
2300 break;
2301
2302 case ACTION_MORALE:
2303 u.disp_morale();
2304 break;
2305
2306 case ACTION_MESSAGES:
2308 break;
2309
2310 case ACTION_HELP:
2312 break;
2313
2314 case ACTION_OPTIONS:
2315 get_options().show( true );
2316 break;
2317
2318 case ACTION_AUTOPICKUP:
2320 break;
2321
2322 case ACTION_AUTONOTES:
2324 break;
2325
2326 case ACTION_SAFEMODE:
2327 get_safemode().show();
2328 break;
2329
2330 case ACTION_COLOR:
2331 all_colors.show_gui();
2332 break;
2333
2334 case ACTION_WORLD_MODS:
2335 world_generator->show_active_world_mods( world_generator->active_world->active_mod_order );
2336 break;
2337
2338 case ACTION_DEBUG:
2340 break; //don't do anything when sharing and not debugger
2341 }
2343 break;
2344
2347 break;
2348
2351 break;
2352
2355 break;
2356
2359 break;
2360
2362 get_options().get_option( "AUTO_FEATURES" ).setNext();
2363 get_options().save();
2364 //~ Auto Features are now ON/OFF
2365 add_msg( _( "%s are now %s." ),
2366 get_options().get_option( "AUTO_FEATURES" ).getMenuText(),
2367 get_option<bool>( "AUTO_FEATURES" ) ? _( "ON" ) : _( "OFF" ) );
2368 break;
2369
2371 get_options().get_option( "AUTO_PULP_BUTCHER" ).setNext();
2372 get_options().save();
2373 //~ Auto Pulp/Pulp Adjacent/Butcher is now set to x
2374 add_msg( _( "%s is now set to %s." ),
2375 get_options().get_option( "AUTO_PULP_BUTCHER" ).getMenuText(),
2376 get_options().get_option( "AUTO_PULP_BUTCHER" ).getValueName() );
2377 break;
2378
2380 get_options().get_option( "AUTO_MINING" ).setNext();
2381 get_options().save();
2382 //~ Auto Mining is now ON/OFF
2383 add_msg( _( "%s is now %s." ),
2384 get_options().get_option( "AUTO_MINING" ).getMenuText(),
2385 get_option<bool>( "AUTO_MINING" ) ? _( "ON" ) : _( "OFF" ) );
2386 break;
2387
2389 if( g->u.get_value( "THIEF_MODE" ) == "THIEF_ASK" ) {
2390 u.set_value( "THIEF_MODE", "THIEF_HONEST" );
2391 u.set_value( "THIEF_MODE_KEEP", "YES" );
2392 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2393 add_msg( _( "You will not pick up other peoples belongings." ) );
2394 } else if( g->u.get_value( "THIEF_MODE" ) == "THIEF_HONEST" ) {
2395 u.set_value( "THIEF_MODE", "THIEF_STEAL" );
2396 u.set_value( "THIEF_MODE_KEEP", "YES" );
2397 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2398 add_msg( _( "You will pick up also those things that belong to others!" ) );
2399 } else if( g->u.get_value( "THIEF_MODE" ) == "THIEF_STEAL" ) {
2400 u.set_value( "THIEF_MODE", "THIEF_ASK" );
2401 u.set_value( "THIEF_MODE_KEEP", "NO" );
2402 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2403 add_msg( _( "You will be reminded not to steal." ) );
2404 } else {
2405 // ERROR
2406 add_msg( _( "THIEF_MODE CONTAINED BAD VALUE [ %s ]!" ), g->u.get_value( "THIEF_MODE" ) );
2407 }
2408 break;
2409
2411 get_options().get_option( "AUTO_FORAGING" ).setNext();
2412 get_options().save();
2413 //~ Auto Foraging is now set to x
2414 add_msg( _( "%s is now set to %s." ),
2415 get_options().get_option( "AUTO_FORAGING" ).getMenuText(),
2416 get_options().get_option( "AUTO_FORAGING" ).getValueName() );
2417 break;
2418
2420 get_options().get_option( "AUTO_PICKUP" ).setNext();
2421 get_options().save();
2422 //~ Auto pickup is now set to x
2423 add_msg( _( "%s is now set to %s." ),
2424 get_options().get_option( "AUTO_PICKUP" ).getMenuText(),
2425 get_options().get_option( "AUTO_PICKUP" ).getValueName() );
2426 break;
2427
2430 break; //don't do anything when sharing and not debugger
2431 }
2432 display_scent();
2433 break;
2434
2437 break; //don't do anything when sharing and not debugger
2438 }
2439 display_scent();
2440 break;
2441
2444 break; //don't do anything when sharing and not debugger
2445 }
2447 break;
2450 break; //don't do anything when sharing and not debugger
2451 }
2453 break;
2456 break; //don't do anything when sharing and not debugger
2457 }
2459 break;
2460
2463 break; //don't do anything when sharing and not debugger
2464 }
2466 break;
2467
2470 break; //don't do anything when sharing and not debugger
2471 }
2473 break;
2474
2477 break; //don't do anything when sharing and not debugger
2478 }
2480 break;
2481
2483 g->debug_submap_grid_overlay = !g->debug_submap_grid_overlay;
2484 break;
2485
2488 break;
2489
2492 break; //don't do anything when sharing and not debugger
2493 }
2495 if( debug_mode ) {
2496 add_msg( m_info, _( "Debug mode ON!" ) );
2497 } else {
2498 add_msg( m_info, _( "Debug mode OFF!" ) );
2499 }
2500 break;
2501
2502 case ACTION_ZOOM_IN:
2503 zoom_in();
2505 break;
2506
2507 case ACTION_ZOOM_OUT:
2508 zoom_out();
2510 break;
2511
2512 case ACTION_ITEMACTION:
2514 break;
2515
2516 case ACTION_AUTOATTACK:
2518 break;
2519
2520 default:
2521 break;
2522 }
2523 }
2524 if( act != ACTION_TIMEOUT ) {
2525 u.mod_moves( -current_turn.moves_elapsed() );
2526 }
2527 gamemode->post_action( act );
2528
2529 u.movecounter = ( !u.is_dead_state() ? ( before_action_moves - u.moves ) : 0 );
2530 dbg( DL::Info ) << string_format( "%s: [%d] %d - %d = %d", action_ident( act ),
2531 to_turn<int>( calendar::turn ), before_action_moves, u.movecounter, u.moves );
2532 return ( !u.is_dead_state() );
2533}
cata::optional< std::string > press_x_if_bound(action_id act)
Definition: action.cpp:466
bool can_action_change_worldstate(const action_id act)
Lookup whether an action can affect the state of the game world.
Definition: action.cpp:345
action_id look_up_action(const std::string &ident)
Lookup an action ID by its unique string identifier.
Definition: action.cpp:415
action_id handle_main_menu()
Show in-game main menu.
Definition: action.cpp:928
point get_delta_from_movement_action(const action_id act, const iso_rotate rot)
Definition: action.cpp:504
action_id handle_action_menu()
Show the action menu.
Definition: action.cpp:648
@ ACTION_SAFEMODE
Open safemode manager.
Definition: action.h:263
@ ACTION_PEEK
Peek through something (e.g.
Definition: action.h:121
@ ACTION_OPEN
Open an item (e.g.
Definition: action.h:99
@ ACTION_CRAFT
Open crafting menu.
Definition: action.h:197
@ ACTION_DROP
Open the drop-item menu.
Definition: action.h:179
@ ACTION_READ
Open the read menu.
Definition: action.h:153
@ ACTION_TOGGLE_AUTO_PICKUP
Turn auto pickup on/off.
Definition: action.h:307
@ ACTION_MOVE_BACK_LEFT
Move towards bottom-left of screen / decelerate and steer left.
Definition: action.h:51
@ ACTION_ZOOM_IN
Zoom view out.
Definition: action.h:285
@ ACTION_EAT
Open the default consume item menu.
Definition: action.h:149
@ ACTION_SMASH
Smash something.
Definition: action.h:103
@ ACTION_ADVANCEDINV
Open the advanced inventory screen.
Definition: action.h:135
@ ACTION_QUICKSAVE
Quicksave the game.
Definition: action.h:225
@ ACTION_HELP
Display help screen.
Definition: action.h:251
@ ACTION_MESSAGES
Display messages screen.
Definition: action.h:249
@ ACTION_ZONES
Open the zone manager.
Definition: action.h:125
@ ACTION_TOGGLE_PIXEL_MINIMAP
Turn pixel minimap on/off.
Definition: action.h:291
@ ACTION_USE
Open the use menu.
Definition: action.h:141
@ ACTION_QUICKLOAD
Quickload the game.
Definition: action.h:227
@ ACTION_LIST_ITEMS
List items and monsters in a given square.
Definition: action.h:123
@ ACTION_DEBUG
Open debug menu.
Definition: action.h:275
@ ACTION_OPTIONS
Display options window.
Definition: action.h:257
@ ACTION_MOVE_FORTH
Move towards top of screen / accelerate.
Definition: action.h:41
@ ACTION_PICK_STYLE
Open the martial-arts style menu.
Definition: action.h:157
@ ACTION_CONSTRUCT
Open construct menu.
Definition: action.h:203
@ ACTION_MOVE_FORTH_RIGHT
Move towards top-right of screen / accelerate and steer right.
Definition: action.h:43
@ ACTION_SORT_ARMOR
Open the armor sorting menu.
Definition: action.h:187
@ ACTION_OPEN_CONSUME
Open the custom consume item menu.
Definition: action.h:151
@ ACTION_MORALE
Display morale effects screen.
Definition: action.h:247
@ ACTION_NULL
Invalid action used for various lookup errors.
Definition: action.h:24
@ ACTION_RESET_MOVE
Reset movement mode to walk
Definition: action.h:63
@ ACTION_CHAT
Chat with something.
Definition: action.h:117
@ ACTION_RELOAD_WIELDED
Attempt to reload wielded object.
Definition: action.h:163
@ ACTION_MOVE_DOWN
Descend a staircase.
Definition: action.h:57
@ ACTION_MISSIONS
Display missions screen.
Definition: action.h:241
@ ACTION_AUTONOTES
Open autonotes manager.
Definition: action.h:261
@ ACTION_WIELD
Open the wield menu.
Definition: action.h:155
@ ACTION_THROW
Open the throw menu.
Definition: action.h:169
@ ACTION_TOGGLE_AUTO_MINING
Turn auto mining on/off.
Definition: action.h:303
@ ACTION_INVENTORY
Open the primary inventory screen.
Definition: action.h:133
@ ACTION_TOGGLE_AUTOSAFE
Turn automatic triggering of safemode on/off.
Definition: action.h:215
@ ACTION_OPEN_MOVEMENT
Open movement mode menu.
Definition: action.h:69
@ ACTION_COMPARE
Open the item compare screen.
Definition: action.h:137
@ ACTION_SCORES
Display scores screen.
Definition: action.h:243
@ ACTION_BUTCHER
Butcher or disassemble objects in current square.
Definition: action.h:115
@ ACTION_SEC_SELECT
Click on a point with secondary mouse button (usually right button)
Definition: action.h:31
@ ACTION_TOGGLE_CROUCH
Toggle crouch on/off.
Definition: action.h:67
@ ACTION_TOGGLE_HOUR_TIMER
Toggle timing of the game hours.
Definition: action.h:323
@ ACTION_SELECT
Click on a point with primary mouse button (usually left button)
Definition: action.h:29
@ ACTION_MAIN_MENU
Display main menu.
Definition: action.h:253
@ ACTION_DISPLAY_SUBMAP_GRID
Toggle submap grid overlay.
Definition: action.h:321
@ ACTION_WAIT
Open wait menu.
Definition: action.h:195
@ ACTION_ACTIONMENU
Open the action menu.
Definition: action.h:287
@ ACTION_DISASSEMBLE
Open disassemble menu.
Definition: action.h:205
@ ACTION_LOOT
Sort out the loot.
Definition: action.h:127
@ ACTION_TOGGLE_FULLSCREEN
Toggle full-screen mode.
Definition: action.h:273
@ ACTION_MAP
Display over-map.
Definition: action.h:237
@ ACTION_MEND
Open the mending menu (e.g.
Definition: action.h:167
@ ACTION_TOGGLE_THIEF_MODE
Toggle permanent attitude to stealing.
Definition: action.h:217
@ ACTION_USE_WIELDED
Use currently wielded item.
Definition: action.h:143
@ ACTION_PL_INFO
Display player status screen.
Definition: action.h:235
@ ACTION_DISPLAY_SCENT_TYPE
Toggle scent type map.
Definition: action.h:279
@ ACTION_TOGGLE_AUTO_FORAGING
Turn auto foraging on/off.
Definition: action.h:305
@ ACTION_FIRE_BURST
Burst-fire the current weapon.
Definition: action.h:173
@ ACTION_BIONICS
Open the bionics menu.
Definition: action.h:183
@ ACTION_CONTROL_VEHICLE
Open vehicle control menu.
Definition: action.h:209
@ ACTION_SAVE
Save the game and quit.
Definition: action.h:223
@ ACTION_MOVE_UP
Ascend a staircase.
Definition: action.h:59
@ ACTION_TOGGLE_PANEL_ADM
Turn admin panel on/off.
Definition: action.h:293
@ ACTION_TOGGLE_AUTO_PULP_BUTCHER
Change auto pulp/butcher mode.
Definition: action.h:301
@ ACTION_TOGGLE_AUTO_TRAVEL_MODE
Turn auto travel mode on/off.
Definition: action.h:211
@ ACTION_COLOR
Open color manager.
Definition: action.h:265
@ ACTION_TIMEOUT
Input timeout.
Definition: action.h:39
@ ACTION_TOGGLE_RUN
Toggle run on/off.
Definition: action.h:65
@ ACTION_FACTIONS
Display factions screen.
Definition: action.h:245
@ ACTION_GRAB
Grab or let go of an object.
Definition: action.h:111
@ ACTION_MOVE_BACK
Move towards bottom of screen / decelerate.
Definition: action.h:49
@ ACTION_CAST_SPELL
Cast a spell (only if any spells are known)
Definition: action.h:177
@ ACTION_DIR_DROP
Drop items in a given direction.
Definition: action.h:181
@ ACTION_AUTOATTACK
Auto select and attack hostile creature within range.
Definition: action.h:189
@ ACTION_CYCLE_MOVE
Cycle run/walk/crouch mode.
Definition: action.h:61
@ ACTION_SKY
Show sky state for trying to predict weather.
Definition: action.h:239
@ ACTION_FIRE
Fire the wielded weapon, or open fire menu if none.
Definition: action.h:171
@ ACTION_PAUSE
Pause an on-going activity.
Definition: action.h:37
@ ACTION_MOVE_BACK_RIGHT
Move towards bottom-right of screen / decelerate and steer right.
Definition: action.h:47
@ ACTION_MUTATIONS
Open the mutations menu.
Definition: action.h:185
@ ACTION_HAUL
Haul pile of items, or let go of them.
Definition: action.h:113
@ ACTION_MOVE_RIGHT
Move / steer right.
Definition: action.h:45
@ ACTION_SLEEP
Open sleep menu.
Definition: action.h:207
@ ACTION_ITEMACTION
Open the item uses menu.
Definition: action.h:289
@ ACTION_MOVE_LEFT
Move / steer left.
Definition: action.h:53
@ ACTION_AUTOPICKUP
Open autopickup manager.
Definition: action.h:259
@ ACTION_SUICIDE
Commit suicide.
Definition: action.h:229
@ NUM_ACTIONS
Not an action, serves as count of enumerated actions.
Definition: action.h:325
@ ACTION_ZOOM_OUT
Zoom view in.
Definition: action.h:283
@ ACTION_SELECT_FIRE_MODE
Change fire mode of the current weapon.
Definition: action.h:175
@ ACTION_UNLOAD
Open the unload item (e.g.
Definition: action.h:165
@ ACTION_RECRAFT
Repeat last craft command.
Definition: action.h:199
@ ACTION_TAKE_OFF
Open the take-off clothing selection menu.
Definition: action.h:147
@ ACTION_PICKUP_FEET
Pick up items from current square.
Definition: action.h:109
@ ACTION_TOGGLE_AUTO_FEATURES
Turn auto features on/off.
Definition: action.h:299
@ ACTION_WORLD_MODS
Open active world mods.
Definition: action.h:267
@ ACTION_TOGGLE_DEBUG_MODE
Toggle debug mode.
Definition: action.h:281
@ ACTION_ORGANIZE
Swap inventory letters.
Definition: action.h:139
@ ACTION_MOVE_FORTH_LEFT
Move towards top-left of screen / accelerate and steer left.
Definition: action.h:55
@ ACTION_RELOAD_TILESET
Reload current tileset.
Definition: action.h:297
@ ACTION_CLOSE
Close an item (e.g.
Definition: action.h:101
@ ACTION_RELOAD_WEAPON
Attempt to reload wielded weapon, then fall back to the load item select menu.
Definition: action.h:161
@ ACTION_RELOAD_ITEM
Open the load item (e.g.
Definition: action.h:159
@ ACTION_PICKUP
Pick up items from current/adjacent squares.
Definition: action.h:107
@ ACTION_LONGCRAFT
Open batch crafting menu.
Definition: action.h:201
@ ACTION_WEAR
Open the wear clothing selection menu.
Definition: action.h:145
void create_advanced_inv()
auto_notes::auto_note_settings & get_auto_notes_settings()
Definition: auto_note.cpp:386
auto_pickup::player_settings & get_auto_pickup()
Definition: auto_pickup.cpp:38
bool tile_iso
Using isometric tileset.
bool debug_mode
Extended debugging mode, can be toggled during game.
bool has_active_mutation(const trait_id &b) const
Definition: mutation.cpp:367
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1583
bool has_active_item(const itype_id &id) const
Whether the player carries an active item of the given item type.
Definition: character.cpp:2537
void place_corpse()
Definition: character.cpp:9920
std::set< tripoint > get_path_avoid() const override
Returns a set of points we do not want to path through.
Definition: character.cpp:9745
bool has_destination_activity() const
bool is_auto_moving() const
void start_destination_activity()
action_id get_next_auto_move_direction()
const pathfinding_settings & get_pathfinding_settings() const override
Returns settings for pathfinding.
Definition: character.cpp:9759
bool is_armed() const
Returns true if the character is wielding something.
Definition: melee.cpp:145
void dismount()
Definition: character.cpp:1232
item weapon
Definition: character.h:1579
void set_value(const std::string &key, const std::string &value)
Definition: creature.cpp:1325
std::string get_value(const std::string &key) const
Definition: creature.cpp:1335
void mod_moves(int nmoves)
Definition: creature.cpp:1402
void cycle_move_mode()
Definition: avatar.cpp:1214
void toggle_map_memory()
Definition: avatar.cpp:117
void toggle_crouch_mode()
Definition: avatar.cpp:1198
void toggle_run_mode()
Definition: avatar.cpp:1189
void disp_morale()
Provides the window and detailed morale data.
Definition: avatar.cpp:985
void reset_move_mode()
Definition: avatar.cpp:1207
void item_action_menu()
void display_radiation()
Definition: game.cpp:11770
void list_missions()
Definition: mission_ui.cpp:22
input_context get_player_input(std::string &action)
bool try_get_left_click_action(action_id &act, const tripoint &mouse_target)
Definition: game.cpp:2602
void wield()
Definition: game.cpp:9101
void set_safe_mode(safe_mode_type mode)
Definition: game.cpp:9174
void reload_wielded(bool prompt=false)
Definition: game.cpp:8934
cata::optional< tripoint > look_around()
Definition: game.cpp:6835
void pickup_feet()
Definition: game.cpp:5892
void zones_manager()
Definition: game.cpp:6360
int turnssincelastmon
Definition: game.h:1069
void display_visibility()
Definition: game.cpp:11684
void display_scent()
Definition: game.cpp:11649
bool save()
Returns false if saving failed.
Definition: game.cpp:3095
void butcher()
Definition: game.cpp:8554
void display_temperature()
Definition: game.cpp:11670
bool auto_travel_mode
Definition: game.h:1066
void zoom_out()
Definition: game.cpp:7302
void toggle_pixel_minimap()
Definition: game.cpp:507
void toggle_debug_hour_timer()
Definition: game.cpp:11716
void display_transparency()
Definition: game.cpp:11777
void list_items_monsters()
Definition: game.cpp:7479
void chat()
Definition: npctalk.cpp:393
void quickload()
Definition: game.cpp:11812
void pickup()
Definition: game.cpp:5870
void vertical_move(int z, bool force, bool peeking=false)
Moves the player vertically.
Definition: game.cpp:10497
void open_consume_item_menu()
void display_lighting()
Definition: game.cpp:11744
void control_vehicle()
Definition: game.cpp:5441
void peek()
Definition: game.cpp:5899
void drop()
Definition: game.cpp:8293
bool try_get_right_click_action(action_id &act, const tripoint &mouse_target)
Definition: game.cpp:2630
void reload_weapon(bool try_everything=true)
Definition: game.cpp:8944
bool check_safe_mode_allowed(bool repeat_safe_mode_warnings=true)
Check whether movement is allowed according to safe mode settings.
Definition: game.cpp:9112
void zoom_in()
Definition: game.cpp:7314
void toggle_fullscreen()
Definition: game.cpp:497
void display_vehicle_ai()
Definition: game.cpp:11677
void reload_item()
Definition: game.cpp:8920
void reload_tileset()
Definition: game.cpp:518
void mark_main_ui_adaptor_resize() const
Definition: game.cpp:3343
void drop_in_direction()
Definition: game.cpp:8298
void display_help()
Definition: help.cpp:140
cata::optional< tripoint > get_coordinates(const catacurses::window &capture_win_)
Get the coordinates associated with the last mouse click (if any).
Definition: input.cpp:1338
input_event get_raw_input()
Temporary method to retrieve the raw input received, so that input_contexts can be used in screens wh...
Definition: input.cpp:1299
action_id display_menu(bool permit_execute_action=false)
Displays the possible actions in the current context and their keybindings.
Definition: input.cpp:999
std::string get_keyname(int ch, input_event_t inp_type, bool portable=false) const
Get the key name associated with the given keyboard keycode.
Definition: input.cpp:415
item_location ammo
Definition: item.h:483
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6290
void gun_cycle_mode()
Switch to the next available firing mode.
Definition: item.cpp:7677
bool is_gunmod() const
Definition: item.cpp:6320
std::map< gun_mode_id, gun_mode > gun_all_modes() const
Get all possible modes for this gun inclusive of any attached gunmods.
Definition: item.cpp:7596
bool has_flag(const std::string &flag) const
Definition: item.cpp:5112
bool gun_set_mode(const gun_mode_id &mode)
Try to set the mode for a gun, returning false if no such mode is possible.
Definition: item.cpp:7668
bool is_outside(const tripoint &p) const
Definition: map.cpp:2572
std::vector< tripoint > route(const tripoint &f, const tripoint &t, const pathfinding_settings &settings, const std::set< tripoint > &pre_closed={{ }}) const
Calculate the best path using A*.
const tripoint & pos() const override
Definition: monster.cpp:255
short ignoring
Definition: monster.h:505
cOpt & get_option(const std::string &name)
Definition: options.cpp:3334
std::string show(bool ingame=false, bool world_options_only=false, const std::function< bool()> &on_quit=nullptr)
Definition: options.cpp:2722
void show_adm()
Definition: panels.cpp:2401
void pause()
Definition: player.cpp:756
item_location ammo_location
Definition: player.h:692
void craft(const tripoint &loc=tripoint_zero)
Start various types of crafts.
Definition: crafting.cpp:334
void disp_info()
Handles and displays detailed character info for the '@' screen.
item::reload_option select_ammo(const item &base, bool prompt=false, bool empty=true) const
Select suitable ammo with which to reload the item.
Definition: player.cpp:2476
void sort_armor()
Draws the UI and handles player input for the armor re-ordering window.
void power_mutations()
Definition: mutation_ui.cpp:89
void use_wielded()
Uses the current wielded weapon.
Definition: player.cpp:3272
int movecounter
Definition: player.h:695
void power_bionics()
Generates and handles the UI for player interaction with installed bionics.
Definition: bionics_ui.cpp:528
void recraft(const tripoint &loc=tripoint_zero)
Definition: crafting.cpp:345
void long_craft(const tripoint &loc=tripoint_zero)
Definition: crafting.cpp:354
void add_rule(const std::string &rule_in, Creature::Attitude attitude_in, int proximity_in, rule_state state_in)
void show()
Definition: safemode_ui.cpp:39
int moves_elapsed()
#define all_colors
Definition: color.h:15
construction_id construction_menu(const bool blueprint)
@ Info
Information (default: enabled).
@ RULE_WHITELISTED
Definition: enums.h:53
@ SAFE_MODE_OFF
Definition: game.h:77
@ QUIT_SAVED
Definition: game.h:70
static const std::string flag_RELOAD_ONE("RELOAD_ONE")
static void open_movement_mode_menu()
static void smash()
static void open()
static const std::string flag_RELOAD_AND_SHOOT("RELOAD_AND_SHOOT")
#define dbg(x)
static void takeoff()
static void read()
static void wait()
static const efftype_id effect_laserlocked("laserlocked")
static void rcdrive(const point &d)
static void wear()
static void close()
static const bionic_id bio_remote("bio_remote")
static void pldrive(const tripoint &p)
static void haul()
static const trait_id trait_SHELL2("SHELL2")
static const trait_id trait_PROF_CHURL("PROF_CHURL")
static void cast_spell()
static void loot()
static void fire()
static void grab()
static void sleep()
static const itype_id itype_radiocontrol("radiocontrol")
help & get_help()
Definition: help.cpp:30
bool isDebugger()
Definition: mapsharing.cpp:65
bool isCompetitive()
Definition: mapsharing.cpp:35
void use_item(avatar &you, item_location &loc)
bool eat_here(avatar &you)
void autoattack(avatar &you, map &m)
void eat(avatar &you)
Eat food or fuel 'E' (or 'a')
void fire_wielded_weapon(avatar &you)
Checks if the wielded weapon is a gun and can be fired then starts interactive aiming.
void plthrow(avatar &you, item_location loc, const cata::optional< tripoint > &blind_throw_from_pos=cata::nullopt)
void mend(avatar &you, item_location loc)
void unload(avatar &you)
void debug()
void close_door(map &m, Character &who, const tripoint &closep)
Handles deducting moves, printing messages (only non-NPCs cause messages), actually closing it,...
Definition: gates.cpp:255
void compare(player &p, const cata::optional< tripoint > &offset)
void common(avatar &you)
void swap_letters(player &p)
void display_visible_weather()
Display overmap like with display() and display the weather that is within line of sight.
void display()
Display overmap centered at the player's position.
options_manager & get_options()
Definition: options.cpp:142
T get_option(const std::string &name)
Definition: options.h:368
static constexpr point point_south_west
Definition: point.h:281
static constexpr point point_north_east
Definition: point.h:277
static constexpr point point_north_west
Definition: point.h:283
An instance of an input, like a keypress etc.
Definition: input.h:95
std::vector< int > sequence
Definition: input.h:101
int get_first_input() const
Definition: input.cpp:100
input_event_t type
Definition: input.h:96
void handbrake()

References _, Creature::A_ANY, achievements_tracker_ptr, act, action, ACTION_ACTIONMENU, ACTION_ADVANCEDINV, ACTION_AUTOATTACK, ACTION_AUTONOTES, ACTION_AUTOPICKUP, ACTION_BIONICS, ACTION_BUTCHER, ACTION_CAST_SPELL, ACTION_CENTER, ACTION_CHAT, ACTION_CLOSE, ACTION_COLOR, ACTION_COMPARE, ACTION_CONSTRUCT, ACTION_CONTROL_VEHICLE, ACTION_CRAFT, ACTION_CYCLE_MOVE, ACTION_DEBUG, ACTION_DIR_DROP, ACTION_DISASSEMBLE, ACTION_DISPLAY_LIGHTING, ACTION_DISPLAY_RADIATION, ACTION_DISPLAY_SCENT, ACTION_DISPLAY_SCENT_TYPE, ACTION_DISPLAY_SUBMAP_GRID, ACTION_DISPLAY_TEMPERATURE, ACTION_DISPLAY_TRANSPARENCY, ACTION_DISPLAY_VEHICLE_AI, ACTION_DISPLAY_VISIBILITY, ACTION_DROP, ACTION_EAT, ACTION_EXAMINE, ACTION_FACTIONS, ACTION_FIRE, ACTION_FIRE_BURST, ACTION_GRAB, ACTION_HAUL, ACTION_HELP, action_ident(), ACTION_IGNORE_ENEMY, ACTION_INVENTORY, ACTION_ITEMACTION, ACTION_KEYBINDINGS, ACTION_LIST_ITEMS, ACTION_LONGCRAFT, ACTION_LOOK, ACTION_LOOT, ACTION_MAIN_MENU, ACTION_MAP, ACTION_MEND, ACTION_MESSAGES, ACTION_MISSIONS, ACTION_MORALE, ACTION_MOVE_BACK, ACTION_MOVE_BACK_LEFT, ACTION_MOVE_BACK_RIGHT, ACTION_MOVE_DOWN, ACTION_MOVE_FORTH, ACTION_MOVE_FORTH_LEFT, ACTION_MOVE_FORTH_RIGHT, ACTION_MOVE_LEFT, ACTION_MOVE_RIGHT, ACTION_MOVE_UP, ACTION_MUTATIONS, ACTION_NULL, ACTION_OPEN, ACTION_OPEN_CONSUME, ACTION_OPEN_MOVEMENT, ACTION_OPTIONS, ACTION_ORGANIZE, ACTION_PAUSE, ACTION_PEEK, ACTION_PICK_STYLE, ACTION_PICKUP, ACTION_PICKUP_FEET, ACTION_PL_INFO, ACTION_QUICKLOAD, ACTION_QUICKSAVE, ACTION_READ, ACTION_RECRAFT, ACTION_RELOAD_ITEM, ACTION_RELOAD_TILESET, ACTION_RELOAD_WEAPON, ACTION_RELOAD_WIELDED, ACTION_RESET_MOVE, ACTION_SAFEMODE, ACTION_SAVE, ACTION_SCORES, ACTION_SEC_SELECT, ACTION_SELECT, ACTION_SELECT_FIRE_MODE, ACTION_SHIFT_E, ACTION_SHIFT_N, ACTION_SHIFT_NE, ACTION_SHIFT_NW, ACTION_SHIFT_S, ACTION_SHIFT_SE, ACTION_SHIFT_SW, ACTION_SHIFT_W, ACTION_SKY, ACTION_SLEEP, ACTION_SMASH, ACTION_SORT_ARMOR, ACTION_SUICIDE, ACTION_TAKE_OFF, ACTION_THROW, ACTION_TIMEOUT, ACTION_TOGGLE_AUTO_FEATURES, ACTION_TOGGLE_AUTO_FORAGING, ACTION_TOGGLE_AUTO_MINING, ACTION_TOGGLE_AUTO_PICKUP, ACTION_TOGGLE_AUTO_PULP_BUTCHER, ACTION_TOGGLE_AUTO_TRAVEL_MODE, ACTION_TOGGLE_AUTOSAFE, ACTION_TOGGLE_CROUCH, ACTION_TOGGLE_DEBUG_MODE, ACTION_TOGGLE_FULLSCREEN, ACTION_TOGGLE_HOUR_TIMER, ACTION_TOGGLE_MAP_MEMORY, ACTION_TOGGLE_PANEL_ADM, ACTION_TOGGLE_PIXEL_MINIMAP, ACTION_TOGGLE_RUN, ACTION_TOGGLE_SAFEMODE, ACTION_TOGGLE_THIEF_MODE, ACTION_UNLOAD, ACTION_USE, ACTION_USE_WIELDED, ACTION_WAIT, ACTION_WEAR, ACTION_WHITELIST_ENEMY, ACTION_WIELD, ACTION_WORLD_MODS, ACTION_ZONES, ACTION_ZOOM_IN, ACTION_ZOOM_OUT, add_msg(), safemode::add_rule(), all_colors, item::reload_option::ammo, player::ammo_location, auto_travel_mode, avatar_action::autoattack(), bio_remote, butcher(), can_action_change_worldstate(), cast_spell(), chat(), check_safe_mode_allowed(), Character::clear_destination(), close(), doors::close_door(), game_menus::inv::common(), game_menus::inv::compare(), construction_menu(), control_vehicle(), Character::controlling_vehicle, player::craft(), create_advanced_inv(), avatar::cycle_move_mode(), dbg, debug_menu::debug(), debug_mode, destination_preview, player::disassemble(), Character::dismount(), player::disp_info(), avatar::disp_morale(), ui::omap::display(), help::display_help(), display_lighting(), input_context::display_menu(), Messages::display_messages(), display_radiation(), display_scent(), display_temperature(), display_transparency(), display_vehicle_ai(), display_visibility(), ui::omap::display_visible_weather(), driving_view_offset, drop(), drop_in_direction(), avatar_action::eat(), avatar_action::eat_here(), effect_laserlocked, examine(), faction_manager_ptr, fire(), avatar_action::fire_wielded_weapon(), flag_RELOAD_AND_SHOOT(), flag_RELOAD_ONE(), g, gamemode, get_auto_notes_settings(), get_auto_pickup(), input_context::get_coordinates(), get_delta_from_movement_action(), input_event::get_first_input(), get_help(), input_manager::get_keyname(), get_kill_tracker(), panel_manager::get_manager(), avatar::get_mon_visible(), Character::get_next_auto_move_direction(), options_manager::get_option(), get_option(), get_options(), Character::get_path_avoid(), Character::get_pathfinding_settings(), get_player_input(), input_context::get_raw_input(), get_safemode(), Creature::get_value(), grab(), item::gun_all_modes(), item::gun_cycle_mode(), item::gun_set_mode(), handbrake(), handle_action_menu(), handle_main_menu(), Character::has_active_bionic(), Character::has_active_item(), Character::has_active_mutation(), Character::has_destination(), Character::has_destination_activity(), Creature::has_effect(), item::has_flag(), Character::has_trait(), haul(), monster::ignoring, Character::in_vehicle, Info, inp_mngr, Character::is_armed(), Character::is_auto_moving(), player::is_dead_state(), item::is_gun(), item::is_gunmod(), Character::is_mounted(), map::is_outside(), MAP_SHARING::isCompetitive(), MAP_SHARING::isDebugger(), item_action_menu(), itype_radiocontrol, list_items_monsters(), list_missions(), player::long_craft(), look_around(), look_up_action(), loot(), m, m_bad, m_info, m_warning, mark_main_ui_adaptor_resize(), Character::martial_arts_data, avatar_action::mend(), MF_RIDEABLE_MECH, Creature::mod_moves(), mostseen, Character::mounted_creature, avatar_action::move(), player::movecounter, Creature::moves, user_turn::moves_elapsed(), om_direction::name(), monster_visible_info::new_seen_mon, no, cata::nullopt, NUM_ACTIONS, open(), open_consume_item_menu(), open_movement_mode_menu(), player::pause(), peek(), pickup(), pickup_feet(), Character::place_corpse(), pldrive(), avatar_action::plthrow(), point_east, point_north, point_north_east, point_north_west, point_south, point_south_east, point_south_west, point_west, point_zero, Character::pos(), monster::pos(), Character::posx(), Character::posy(), Character::posz(), player::power_bionics(), player::power_mutations(), press_x(), press_x_if_bound(), query_yn(), quickload(), quicksave(), QUIT_DIED, QUIT_SAVED, QUIT_SUICIDE, QUIT_WATCH, rcdrive(), read(), player::recraft(), reload_item(), reload_tileset(), reload_weapon(), reload_wielded(), remoteveh(), Creature::remove_effect(), avatar::reset_move_mode(), rl_dist(), map::route(), RULE_WHITELISTED, safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAFE_MODE_STOP, safe_mode_warning_logged, save(), options_manager::save(), Character::sees(), SEEX, player::select_ammo(), input_event::sequence, Character::set_destination(), set_safe_mode(), Creature::set_value(), options_manager::cOpt::setNext(), auto_pickup::player_settings::show(), safemode::show(), options_manager::show(), panel_manager::show_adm(), auto_notes::auto_note_settings::show_gui(), show_scores_ui(), sleep(), smash(), player::sort_armor(), Character::start_destination_activity(), stats(), string_format(), game_menus::inv::swap_letters(), takeoff(), tile_iso, avatar::toggle_crouch_mode(), toggle_debug_hour_timer(), toggle_fullscreen(), avatar::toggle_map_memory(), toggle_pixel_minimap(), avatar::toggle_run_mode(), trait_PROF_CHURL, trait_SHELL2, tripoint_above, tripoint_below, try_get_left_click_action(), try_get_right_click_action(), calendar::turn, turnssincelastmon, input_event::type, u, avatar_action::unload(), uquit, avatar_action::use_item(), use_tiles, player::use_wielded(), user_action_counter, map::veh_at(), vertical_move(), player::view_offset, w_terrain, wait(), Character::weapon, wear(), wield(), world_generator, point::x, tripoint::x, point::y, tripoint::y, yes, zones_manager(), zoom_in(), and zoom_out().

Referenced by do_turn().

◆ handle_key_blocking_activity()

void game::handle_key_blocking_activity ( )
private

Definition at line 2053 of file game.cpp.

2054{
2056 const std::string action = ctxt.handle_input( 0 );
2057 bool refresh = true;
2058 if( action == "pause" ) {
2060 cancel_activity_query( _( "Confirm:" ) );
2061 }
2062 } else if( action == "player_data" ) {
2063 u.disp_info();
2064 } else if( action == "messages" ) {
2066 } else if( action == "help" ) {
2068 } else if( action != "HELP_KEYBINDINGS" ) {
2069 refresh = false;
2070 }
2071 if( refresh ) {
2074 }
2075}
bool cancel_activity_query(const std::string &text)
Asks if the player wants to cancel their activity, and if so cancels it.
Definition: game.cpp:1838
const std::string & handle_input()
Handles input and returns the next action in the queue.
Definition: input.cpp:854
bool interruptable_with_kb
Controls whether this activity can be cancelled with 'pause' action.
void refresh()

References _, action, Character::activity, cancel_activity_query(), player::disp_info(), help::display_help(), Messages::display_messages(), get_default_mode_input_context(), get_help(), input_context::handle_input(), player_activity::interruptable_with_kb, ui_manager::redraw(), catacurses::refresh(), refresh_display(), and u.

Referenced by process_voluntary_act_interrupt().

◆ handle_mouseview()

bool game::handle_mouseview ( input_context ctxt,
std::string &  action 
)
private

Definition at line 2310 of file game.cpp.

2311{
2312 cata::optional<tripoint> liveview_pos;
2313
2314 do {
2315 action = ctxt.handle_input();
2316 if( action == "MOUSE_MOVE" ) {
2317 const cata::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
2318 if( mouse_pos && ( !liveview_pos || *mouse_pos != *liveview_pos ) ) {
2319 liveview_pos = mouse_pos;
2320 liveview.show( *liveview_pos );
2321 } else if( !mouse_pos ) {
2322 liveview_pos.reset();
2323 liveview.hide();
2324 }
2326 }
2327 } while( action == "MOUSE_MOVE" ); // Freeze animation when moving the mouse
2328
2329 if( action != "TIMEOUT" ) {
2330 // Keyboard event, break out of animation loop
2331 liveview.hide();
2332 return false;
2333 }
2334
2335 // Mouse movement or un-handled key
2336 return true;
2337}
void reset() noexcept
Definition: optional.h:155
void hide()
Definition: live_view.cpp:33
void show(const tripoint &p)
Definition: live_view.cpp:38

References action, input_context::get_coordinates(), input_context::handle_input(), live_view::hide(), liveview, ui_manager::redraw(), cata::optional< T >::reset(), live_view::show(), and w_terrain.

Referenced by get_player_input().

◆ has_gametype()

bool game::has_gametype ( ) const

Definition at line 621 of file game.cpp.

622{
623 return gamemode && gamemode->id() != SGAME_NULL;
624}

References gamemode, and SGAME_NULL.

◆ init_autosave()

void game::init_autosave ( )
private

Definition at line 11784 of file game.cpp.

11785{
11787 last_save_timestamp = time( nullptr );
11788}

References last_save_timestamp, and moves_since_last_save.

Referenced by load(), and start_game().

◆ inv_map_splice()

item_location game::inv_map_splice ( item_filter  filter,
const std::string &  title,
int  radius = 0,
const std::string &  none_message = "" 
)

Custom-filtered menu for inventory and nearby items and those that within specified radius.

Definition at line 392 of file game_inventory.cpp.

394{
396 title, radius, none_message );
397}
static item_location_filter convert_filter(const item_filter &filter)
static item_location inv_internal(player &u, const inventory_selector_preset &preset, const std::string &title, int radius, const std::string &none_message, const std::string &hint=std::string())
std::string title(holiday current_holiday)
Definition: path_info.cpp:330

References convert_filter(), inv_internal(), PATH_INFO::title(), and u.

Referenced by reload_item().

◆ invalidate_main_ui_adaptor()

void game::invalidate_main_ui_adaptor ( ) const

◆ inventory_item_menu()

int game::inventory_item_menu ( item_location  locThisItem,
const std::function< int()> &  startx = []() { return 0; },
const std::function< int()> &  width = []() { return 50; },
inventory_item_menu_positon  position = RIGHT_OF_INFO 
)

Definition at line 2085 of file game.cpp.

2089{
2090 int cMenu = static_cast<int>( '+' );
2091
2092 item &oThisItem = *locThisItem;
2093 if( u.has_item( oThisItem ) ) {
2094#if defined(__ANDROID__)
2095 if( get_option<bool>( "ANDROID_INVENTORY_AUTOADD" ) ) {
2096 add_key_to_quick_shortcuts( oThisItem.invlet, "INVENTORY", false );
2097 }
2098#endif
2099
2100 std::vector<iteminfo> vThisItem;
2101 std::vector<iteminfo> vDummy;
2102
2103 const bool bHPR = get_auto_pickup().has_rule( &oThisItem );
2104 const bool cant_unwield_weapon = u.weapon.has_flag( "NO_UNWIELD" );
2105 const bool cant_drop_this = cant_unwield_weapon && u.is_wielding( oThisItem );
2106 const hint_rating rate_wield_item = cant_unwield_weapon ? hint_rating::cant :
2108 const hint_rating rate_drop_item = cant_drop_this ? hint_rating::cant :
2110
2111 uilist action_menu;
2112 action_menu.allow_anykey = true;
2113 const auto addentry = [&]( const char key, const std::string & text, const hint_rating hint ) {
2114 // The char is used as retval from the uilist *and* as hotkey.
2115 action_menu.addentry( key, true, key, text );
2116 auto &entry = action_menu.entries.back();
2117 switch( hint ) {
2118 case hint_rating::cant:
2119 entry.text_color = c_light_gray;
2120 break;
2121 case hint_rating::iffy:
2122 entry.text_color = c_light_red;
2123 break;
2124 case hint_rating::good:
2125 entry.text_color = c_light_green;
2126 break;
2127 }
2128 };
2129 addentry( 'a', pgettext( "action", "activate" ), u.rate_action_use( oThisItem ) );
2130 addentry( 'R', pgettext( "action", "read" ), u.rate_action_read( oThisItem ) );
2131 addentry( 'E', pgettext( "action", "eat" ), u.rate_action_eat( oThisItem ) );
2132 addentry( 'W', pgettext( "action", "wear" ), u.rate_action_wear( oThisItem ) );
2133 addentry( 'w', pgettext( "action", "wield" ), rate_wield_item );
2134 addentry( 't', pgettext( "action", "throw" ), rate_drop_item );
2135 addentry( 'c', pgettext( "action", "change side" ), u.rate_action_change_side( oThisItem ) );
2136 addentry( 'T', pgettext( "action", "take off" ), u.rate_action_takeoff( oThisItem ) );
2137 addentry( 'd', pgettext( "action", "drop" ), rate_drop_item );
2138 addentry( 'U', pgettext( "action", "unload" ), u.rate_action_unload( oThisItem ) );
2139 addentry( 'r', pgettext( "action", "reload" ), u.rate_action_reload( oThisItem ) );
2140 addentry( 'p', pgettext( "action", "part reload" ), u.rate_action_reload( oThisItem ) );
2141 addentry( 'm', pgettext( "action", "mend" ), u.rate_action_mend( oThisItem ) );
2142 addentry( 'D', pgettext( "action", "disassemble" ), u.rate_action_disassemble( oThisItem ) );
2143
2144 if( oThisItem.is_favorite ) {
2145 addentry( 'f', pgettext( "action", "unfavorite" ), hint_rating::good );
2146 } else {
2147 addentry( 'f', pgettext( "action", "favorite" ), hint_rating::good );
2148 }
2149
2150 addentry( '=', pgettext( "action", "reassign" ), hint_rating::good );
2151
2152 if( bHPR ) {
2153 addentry( '-', _( "Autopickup" ), hint_rating::iffy );
2154 } else {
2155 addentry( '+', _( "Autopickup" ), hint_rating::good );
2156 }
2157
2158 int iScrollPos = 0;
2159 oThisItem.info( true, vThisItem );
2160
2161 action_menu.w_y_setup = 0;
2162 action_menu.w_x_setup = [&]( const int popup_width ) -> int {
2163 switch( position )
2164 {
2165 default:
2167 return 0;
2168 case LEFT_OF_INFO:
2169 return iStartX() - popup_width;
2170 case RIGHT_OF_INFO:
2171 return iStartX() + iWidth();
2172 case LEFT_TERMINAL_EDGE:
2173 return TERMX - popup_width;
2174 }
2175 };
2176 // Filtering isn't needed, the number of entries is manageable.
2177 action_menu.filtering = false;
2178 // Default menu border color is different, this matches the border of the item info window.
2179 action_menu.border_color = BORDER_COLOR;
2180
2181 item_info_data data( oThisItem.tname(), oThisItem.type_name(), vThisItem, vDummy, iScrollPos );
2182 data.without_getch = true;
2183
2184 catacurses::window w_info;
2185 int iScrollHeight = 0;
2186
2187 std::unique_ptr<ui_adaptor> ui = std::make_unique<ui_adaptor>();
2188 ui->on_screen_resize( [&]( ui_adaptor & ui ) {
2189 w_info = catacurses::newwin( TERMY, iWidth(), point( iStartX(), 0 ) );
2190 iScrollHeight = TERMY - 2;
2191 ui.position_from_window( w_info );
2192 } );
2193 ui->mark_resize();
2194
2195 ui->on_redraw( [&]( const ui_adaptor & ) {
2196 draw_item_info( w_info, data );
2197 } );
2198
2199 bool exit = false;
2200 do {
2201 const int prev_selected = action_menu.selected;
2202 action_menu.query( false );
2203 if( action_menu.ret >= 0 ) {
2204 cMenu = action_menu.ret; /* Remember: hotkey == retval, see addentry above. */
2205 } else if( action_menu.ret == UILIST_UNBOUND && action_menu.keypress == KEY_RIGHT ) {
2206 // Simulate KEY_RIGHT == '\n' (confirm currently selected entry) for compatibility with old version.
2207 // TODO: ideally this should be done in the uilist, maybe via a callback.
2208 cMenu = action_menu.ret = action_menu.entries[action_menu.selected].retval;
2209 } else if( action_menu.keypress == KEY_PPAGE || action_menu.keypress == KEY_NPAGE ) {
2210 cMenu = action_menu.keypress;
2211 // Prevent the menu from scrolling with this key. TODO: Ideally the menu
2212 // could be instructed to ignore these two keys instead of scrolling.
2213 action_menu.selected = prev_selected;
2214 action_menu.fselected = prev_selected;
2215 action_menu.vshift = 0;
2216 } else {
2217 cMenu = 0;
2218 }
2219
2220 if( action_menu.ret != UILIST_WAIT_INPUT && action_menu.ret != UILIST_UNBOUND ) {
2221 exit = true;
2222 ui = nullptr;
2223 }
2224
2225 switch( cMenu ) {
2226 case 'a':
2227 avatar_action::use_item( u, locThisItem );
2228 break;
2229 case 'E':
2230 avatar_action::eat( u, locThisItem );
2231 break;
2232 case 'W':
2233 u.wear( oThisItem );
2234 break;
2235 case 'w':
2236 wield( locThisItem );
2237 break;
2238 case 't':
2239 avatar_action::plthrow( u, locThisItem );
2240 break;
2241 case 'c':
2242 u.change_side( locThisItem );
2243 break;
2244 case 'T':
2245 u.takeoff( oThisItem );
2246 break;
2247 case 'd':
2248 u.drop( locThisItem, u.pos() );
2249 break;
2250 case 'U':
2251 unload( locThisItem );
2252 break;
2253 case 'r':
2254 reload( locThisItem );
2255 break;
2256 case 'p':
2257 reload( locThisItem, true );
2258 break;
2259 case 'm':
2260 avatar_action::mend( u, locThisItem );
2261 break;
2262 case 'R':
2263 u.read( locThisItem );
2264 break;
2265 case 'D':
2266 u.disassemble( locThisItem, false );
2267 break;
2268 case 'f':
2269 oThisItem.is_favorite = !oThisItem.is_favorite;
2270 break;
2271 case '=':
2272 game_menus::inv::reassign_letter( u, oThisItem );
2273 break;
2274 case KEY_PPAGE:
2275 iScrollPos -= iScrollHeight;
2276 if( ui ) {
2277 ui->invalidate_ui();
2278 }
2279 break;
2280 case KEY_NPAGE:
2281 iScrollPos += iScrollHeight;
2282 if( ui ) {
2283 ui->invalidate_ui();
2284 }
2285 break;
2286 case '+':
2287 if( !bHPR ) {
2288 get_auto_pickup().add_rule( &oThisItem );
2289 add_msg( m_info, _( "'%s' added to character pickup rules." ), oThisItem.tname( 1,
2290 false ) );
2291 }
2292 break;
2293 case '-':
2294 if( bHPR ) {
2295 get_auto_pickup().remove_rule( &oThisItem );
2296 add_msg( m_info, _( "'%s' removed from character pickup rules." ), oThisItem.tname( 1,
2297 false ) );
2298 }
2299 break;
2300 default:
2301 break;
2302 }
2303 } while( !exit );
2304 }
2305 return cMenu;
2306}
hint_rating rate_action_change_side(const item &it) const
Used to determine player feedback on item use for the inventory code.
Definition: character.cpp:3564
bool is_wielding(const item &target) const
Definition: character.cpp:3114
bool change_side(item &it, bool interactive=true)
Swap side on which item is worn; returns false on fail.
Definition: character.cpp:3577
hint_rating rate_action_eat(const item &it) const
void remove_rule(const item *it)
bool has_rule(const item *it)
void add_rule(const item *it)
hint_rating rate_action_read(const item &it) const
Definition: avatar.cpp:933
bool read(item_location loc, bool continuous=false)
Handles reading effects and returns true if activity started.
Definition: avatar.cpp:367
bool unload(item_location loc)
Definition: game.cpp:9008
void reload(item_location &loc, bool prompt=false, bool empty=true)
Definition: game.cpp:8829
bool is_favorite
Definition: item.h:2231
std::string info(bool showtext=false) const
Return all the information about the item and its type.
Definition: item.cpp:1095
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9518
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4364
char invlet
Definition: item.h:2229
hint_rating rate_action_mend(const item &it) const
Definition: player.cpp:3339
cata::optional< std::list< item >::iterator > wear(int pos, bool interactive=true)
Wear item; returns false on fail.
Definition: player.cpp:2916
hint_rating rate_action_takeoff(const item &it) const
Definition: player.cpp:2966
hint_rating rate_action_reload(const item &it) const
Definition: player.cpp:3277
hint_rating rate_action_wear(const item &it) const
Definition: player.cpp:2681
hint_rating rate_action_disassemble(const item &it)
Definition: player.cpp:3348
hint_rating rate_action_unload(const item &it) const
Definition: player.cpp:3302
bool takeoff(item &it, std::list< item > *res=nullptr)
Takes off an item, returning false on fail.
Definition: player.cpp:3020
hint_rating rate_action_use(const item &it) const
Used to determine player feedback on item use for the inventory code.
Definition: player.cpp:3361
nc_color border_color
Definition: ui.h:328
int keypress
Definition: ui.h:413
bool filtering
Definition: ui.h:354
pos_scalar w_x_setup
Definition: ui.h:337
int fselected
Definition: ui.h:388
int selected
Definition: ui.h:415
bool allow_anykey
Definition: ui.h:360
int vshift
Definition: ui.h:386
std::vector< uilist_entry > entries
Definition: ui.h:323
bool has_item(const item &it) const
Returns true if this visitable instance contains the item.
Definition: visitable.cpp:93
static constexpr int KEY_NPAGE
Definition: input.h:65
static constexpr int KEY_PPAGE
Definition: input.h:66
static constexpr int KEY_RIGHT
Definition: input.h:40
hint_rating
Hint value used in a hack to decide text color.
Definition: item.h:2254
@ iffy
Item should display as red.
@ good
Item should display as green.
@ cant
Item should display as gray.
void reassign_letter(player &p, item &it)
input_event draw_item_info(const int iLeft, const int iWidth, const int iTop, const int iHeight, item_info_data &data)
Definition: output.cpp:793
#define BORDER_COLOR
Definition: output.h:135
const int UILIST_UNBOUND
Definition: ui.h:27
const int UILIST_WAIT_INPUT
Definition: ui.h:26

References _, add_msg(), auto_pickup::player_settings::add_rule(), uilist::addentry(), uilist::allow_anykey, BORDER_COLOR, uilist::border_color, c_light_gray, c_light_green, c_light_red, cant, Character::change_side(), player::disassemble(), draw_item_info(), Character::drop(), avatar_action::eat(), uilist::entries, uilist::filtering, uilist::fselected, get_auto_pickup(), good, item::has_flag(), visitable< T >::has_item(), auto_pickup::player_settings::has_rule(), iffy, item::info(), item::invlet, item::is_favorite, Character::is_wielding(), KEY_NPAGE, KEY_PPAGE, KEY_RIGHT, uilist::keypress, LEFT_OF_INFO, LEFT_TERMINAL_EDGE, m_info, avatar_action::mend(), catacurses::newwin(), pgettext(), avatar_action::plthrow(), Character::pos(), uilist::query(), Character::rate_action_change_side(), player::rate_action_disassemble(), Character::rate_action_eat(), player::rate_action_mend(), avatar::rate_action_read(), player::rate_action_reload(), player::rate_action_takeoff(), player::rate_action_unload(), player::rate_action_use(), player::rate_action_wear(), avatar::read(), game_menus::inv::reassign_letter(), reload(), auto_pickup::player_settings::remove_rule(), uilist::ret, RIGHT_OF_INFO, RIGHT_TERMINAL_EDGE, uilist::selected, player::takeoff(), TERMX, TERMY, item::tname(), item::type_name(), u, UILIST_UNBOUND, UILIST_WAIT_INPUT, unload(), avatar_action::use_item(), uilist::vshift, uilist::w_x_setup, uilist::w_y_setup, Character::weapon, player::wear(), wield(), and item_info_data::without_getch.

◆ is_core_data_loaded()

bool game::is_core_data_loaded ( ) const

Returns whether the core data is currently loaded.

Definition at line 430 of file game.cpp.

431{
433}
bool is_data_finalized() const
Returns whether the data is finalized and ready to be utilized.
Definition: init.h:167

References DynamicDataLoader::get_instance(), and DynamicDataLoader::is_data_finalized().

◆ is_dangerous_tile()

bool game::is_dangerous_tile ( const tripoint dest_loc) const

Definition at line 9241 of file game.cpp.

9242{
9243 return !( get_dangerous_tile( dest_loc ).empty() );
9244}
std::vector< std::string > get_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:9263

References get_dangerous_tile().

Referenced by walk_move().

◆ is_empty()

bool game::is_empty ( const tripoint p)

Returns true if there is no player, NPC, or monster on the tile and move_cost > 0.

Definition at line 5137 of file game.cpp.

5138{
5139 return ( m.passable( p ) || m.has_flag( "LIQUID", p ) ) &&
5140 critter_at( p ) == nullptr;
5141}

References critter_at(), map::has_flag(), m, and map::passable().

Referenced by grabbed_furn_move(), monmove(), place_player(), and update_stair_monsters().

◆ is_game_over()

bool game::is_game_over ( )
private

Definition at line 2675 of file game.cpp.

2676{
2677 if( uquit == QUIT_WATCH ) {
2678 // deny player movement and dodging
2679 u.moves = 0;
2680 // prevent pain from updating
2681 u.set_pain( 0 );
2682 // prevent dodging
2683 u.dodges_left = 0;
2684 return false;
2685 }
2686 if( uquit == QUIT_DIED ) {
2687 if( u.in_vehicle ) {
2688 m.unboard_vehicle( u.pos() );
2689 }
2690 u.place_corpse();
2691 return true;
2692 }
2693 if( uquit == QUIT_SUICIDE ) {
2694 if( u.in_vehicle ) {
2695 m.unboard_vehicle( u.pos() );
2696 }
2697 return true;
2698 }
2699 if( uquit != QUIT_NO ) {
2700 return true;
2701 }
2702 // is_dead_state() already checks hp_torso && hp_head, no need to for loop it
2703 if( u.is_dead_state() ) {
2705 if( get_option<std::string>( "DEATHCAM" ) == "always" ) {
2706 uquit = QUIT_WATCH;
2707 } else if( get_option<std::string>( "DEATHCAM" ) == "ask" ) {
2708 uquit = query_yn( _( "Watch the last moments of your life…?" ) ) ?
2710 } else if( get_option<std::string>( "DEATHCAM" ) == "never" ) {
2711 uquit = QUIT_DIED;
2712 } else {
2713 // Something funky happened here, just die.
2714 dbg( DL::Error ) << "no deathcam option given to options, defaulting to QUIT_DIED";
2715 uquit = QUIT_DIED;
2716 }
2717 return is_game_over();
2718 }
2719 return false;
2720}
int dodges_left
Definition: character.h:616
void set_pain(int npain) override
Sets new intensity of pain an reacts to it.
Definition: player.cpp:1119
@ Error
Error (default: enabled).
#define dbg(x)
Definition: game.cpp:186
void deactivate()
Definition: messages.cpp:357

References _, dbg, Messages::deactivate(), Character::dodges_left, Error, Character::in_vehicle, player::is_dead_state(), is_game_over(), m, Creature::moves, Character::place_corpse(), Character::pos(), query_yn(), QUIT_DIED, QUIT_NO, QUIT_SUICIDE, QUIT_WATCH, player::set_pain(), u, map::unboard_vehicle(), and uquit.

Referenced by do_turn(), and is_game_over().

◆ is_hostile_nearby()

Creature * game::is_hostile_nearby ( )

Definition at line 3934 of file game.cpp.

3935{
3936 int distance = ( get_option<int>( "SAFEMODEPROXIMITY" ) <= 0 ) ? MAX_VIEW_DISTANCE :
3937 get_option<int>( "SAFEMODEPROXIMITY" );
3938 return is_hostile_within( distance );
3939}
Creature * is_hostile_within(int distance)
Definition: game.cpp:3946

References is_hostile_within(), and MAX_VIEW_DISTANCE.

◆ is_hostile_very_close()

Creature * game::is_hostile_very_close ( )

Definition at line 3941 of file game.cpp.

3942{
3944}
static constexpr int DANGEROUS_PROXIMITY
Definition: game.cpp:188

References DANGEROUS_PROXIMITY, and is_hostile_within().

Referenced by butcher(), and process_voluntary_act_interrupt().

◆ is_hostile_within()

Creature * game::is_hostile_within ( int  distance)
private

Definition at line 3946 of file game.cpp.

3947{
3948 for( auto &critter : u.get_visible_creatures( distance ) ) {
3949 if( u.attitude_to( *critter ) == Creature::A_HOSTILE ) {
3950 return critter;
3951 }
3952 }
3953
3954 return nullptr;
3955}
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
std::vector< Creature * > get_visible_creatures(int range) const
Returns all creatures that this player can see and that are in the given range.
@ A_HOSTILE
Definition: creature.h:169

References Creature::A_HOSTILE, Character::attitude_to(), Character::get_visible_creatures(), and u.

Referenced by is_hostile_nearby(), and is_hostile_very_close().

◆ is_in_sunlight()

bool game::is_in_sunlight ( const tripoint p)

Returns true if p is outdoors and it is sunny.

Definition at line 5143 of file game.cpp.

5144{
5145 return weather::is_in_sunlight( m, p, get_weather().weather_id );
5146}
bool is_in_sunlight(const map &m, const tripoint &p, const weather_type_id &weather)
Definition: weather.cpp:1162

References get_weather, weather::is_in_sunlight(), and m.

Referenced by process_artifact().

◆ is_in_viewport()

bool game::is_in_viewport ( const tripoint p,
int  margin = 0 
) const

Definition at line 3580 of file game.cpp.

3581{
3582 const tripoint diff( u.pos() + u.view_offset - p );
3583
3584 return ( std::abs( diff.x ) <= getmaxx( w_terrain ) / 2 - margin ) &&
3585 ( std::abs( diff.y ) <= getmaxy( w_terrain ) / 2 - margin );
3586}

References catacurses::getmaxx(), catacurses::getmaxy(), Character::pos(), u, player::view_offset, w_terrain, tripoint::x, and tripoint::y.

◆ is_sheltered()

bool game::is_sheltered ( const tripoint p)

Returns true if p is indoors, underground, or in a car.

Definition at line 5148 of file game.cpp.

5149{
5150 return weather::is_sheltered( m, p );
5151}
bool is_sheltered(const map &m, const tripoint &p)
Definition: weather.cpp:1153

References weather::is_sheltered(), and m.

◆ is_zones_manager_open()

bool game::is_zones_manager_open ( ) const

Definition at line 6290 of file game.cpp.

6291{
6292 return zones_manager_open;
6293}
bool zones_manager_open
Is Zone manager open or not - changes graphics of some zone tiles.
Definition: game.h:1101

References zones_manager_open.

◆ item_action_menu()

void game::item_action_menu ( )
private

Definition at line 231 of file item_action.cpp.

232{
233 const auto &gen = item_action_generator::generator();
234 const action_map &item_actions = gen.get_item_action_map();
235
236 // HACK: A bit of a hack for now. If more pseudos get implemented, this should be un-hacked
237 std::vector<item *> pseudos;
238 item toolset( "toolset", calendar::turn );
239 if( u.has_active_bionic( bio_tools ) ) {
240 pseudos.push_back( &toolset );
241 }
242 item bio_claws_item( static_cast<std::string>( bio_claws_weapon ), calendar::turn );
243 if( u.has_active_bionic( bio_claws ) ) {
244 pseudos.push_back( &bio_claws_item );
245 }
246
247 item_action_map iactions = gen.map_actions_to_items( u, pseudos );
248 if( iactions.empty() ) {
249 popup( _( "You don't have any items with registered uses" ) );
250 }
251
252 uilist kmenu;
253 kmenu.text = _( "Execute which action?" );
254 kmenu.input_category = "ITEM_ACTIONS";
255 input_context ctxt( "ITEM_ACTIONS" );
256 for( const auto &id : item_actions ) {
257 ctxt.register_action( id.first, id.second.name );
258 kmenu.additional_actions.emplace_back( id.first, id.second.name );
259 }
260 actmenu_cb callback( item_actions );
261 kmenu.callback = &callback;
262 int num = 0;
263
264 const auto assigned_action = [&iactions]( const item_action_id & action ) {
265 return iactions.find( action ) != iactions.end();
266 };
267
268 std::vector<std::tuple<item_action_id, std::string, std::string>> menu_items;
269 // Sorts menu items by action.
270 using Iter = decltype( menu_items )::iterator;
271 const auto sort_menu = []( Iter from, Iter to ) {
272 std::sort( from, to, []( const std::tuple<item_action_id, std::string, std::string> &lhs,
273 const std::tuple<item_action_id, std::string, std::string> &rhs ) {
274 return std::get<1>( lhs ).compare( std::get<1>( rhs ) ) < 0;
275 } );
276 };
277 // Add mapped actions to the menu vector.
278 std::transform( iactions.begin(), iactions.end(), std::back_inserter( menu_items ),
279 []( const std::pair<item_action_id, item *> &elem ) {
280 std::string ss = elem.second->display_name();
281 if( elem.second->ammo_required() ) {
282 ss += string_format( " (%d/%d)", elem.second->ammo_required(), elem.second->ammo_remaining() );
283 }
284
285 const auto method = elem.second->get_use( elem.first );
286 if( method ) {
287 return std::make_tuple( method->get_type(), method->get_name(), ss );
288 } else {
289 return std::make_tuple( errstring, std::string( "NO USE FUNCTION" ), ss );
290 }
291 } );
292 // Sort mapped actions.
293 sort_menu( menu_items.begin(), menu_items.end() );
294 // Add unmapped but binded actions to the menu vector.
295 for( const auto &elem : item_actions ) {
296 if( key_bound_to( ctxt, elem.first ) != '\0' && !assigned_action( elem.first ) ) {
297 menu_items.emplace_back( elem.first, gen.get_action_name( elem.first ), "-" );
298 }
299 }
300 // Sort unmapped actions.
301 auto iter = menu_items.begin();
302 std::advance( iter, iactions.size() );
303 sort_menu( iter, menu_items.end() );
304 // Determine max lengths, to print the menu nicely.
305 std::pair<int, int> max_len;
306 for( const auto &elem : menu_items ) {
307 max_len.first = std::max( max_len.first, utf8_width( std::get<1>( elem ), true ) );
308 max_len.second = std::max( max_len.second, utf8_width( std::get<2>( elem ), true ) );
309 }
310 // Fill the menu.
311 for( const auto &elem : menu_items ) {
312 std::string ss;
313 ss += std::get<1>( elem );
314 ss += std::string( max_len.first - utf8_width( std::get<1>( elem ), true ), ' ' );
315 ss += std::string( 4, ' ' );
316
317 ss += std::get<2>( elem );
318 ss += std::string( max_len.second - utf8_width( std::get<2>( elem ), true ), ' ' );
319
320 const char bind = key_bound_to( ctxt, std::get<0>( elem ) );
321 const bool enabled = assigned_action( std::get<0>( elem ) );
322
323 kmenu.addentry( num, enabled, bind, ss );
324 num++;
325 }
326
327 kmenu.query();
328 if( kmenu.ret < 0 || kmenu.ret >= static_cast<int>( iactions.size() ) ) {
329 return;
330 }
331
332 const item_action_id action = std::get<0>( menu_items[kmenu.ret] );
333 item *it = iactions[action];
334
335 u.invoke_item( it, action );
336
337 u.inv.restack( u );
338 u.inv.unsort();
339}
inventory inv
Definition: character.h:1577
bool invoke_item(item *, const tripoint &pt) override
Asks how to use the item (if it has more than one use_method) and uses it.
Definition: avatar.cpp:1283
void restack(player &p)
Definition: inventory.cpp:398
void unsort()
Definition: inventory.cpp:226
static item_action_generator & generator()
Definition: item_action.h:32
std::string input_category
Definition: ui.h:325
std::vector< std::pair< std::string, translation > > additional_actions
Definition: ui.h:326
static char key_bound_to(const input_context &ctxt, const item_action_id &act)
Definition: item_action.cpp:47
static const bionic_id bio_claws("bio_claws")
static const bionic_id bio_tools("bio_tools")
static const bionic_id bio_claws_weapon("bio_claws_weapon")
std::string item_action_id
Definition: item_action.h:16
std::map< item_action_id, item_action > action_map
Definition: item_action.h:18
std::map< item_action_id, item * > item_action_map
Definition: item_action.h:17

References _, action, uilist::additional_actions, bio_claws, bio_claws_weapon, bio_tools, uilist::callback, item_action_generator::generator(), Character::has_active_bionic(), uilist::input_category, num, popup(), input_context::register_action(), second, uilist::text, iexamine::transform(), calendar::turn, and u.

Referenced by handle_action().

◆ knockback() [1/2]

void game::knockback ( const tripoint s,
const tripoint t,
int  force,
int  stun,
int  dam_mult 
)

Definition at line 4570 of file game.cpp.

4571{
4572 std::vector<tripoint> traj;
4573 traj.clear();
4574 traj = line_to( s, t, 0, 0 );
4575 traj.insert( traj.begin(), s ); // how annoying, line_to() doesn't include the originating point!
4576 traj = continue_line( traj, force );
4577 traj.insert( traj.begin(), t ); // how annoying, continue_line() doesn't either!
4578
4579 knockback( traj, stun, dam_mult );
4580}
std::vector< coords::coord_point< Point, Origin, Scale > > line_to(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:548
std::vector< tripoint > continue_line(const std::vector< tripoint > &line, const int distance)
Definition: line.cpp:408

References continue_line(), knockback(), and line_to().

Referenced by forced_door_closing(), and knockback().

◆ knockback() [2/2]

void game::knockback ( std::vector< tripoint > &  traj,
int  stun,
int  dam_mult 
)

Definition at line 4586 of file game.cpp.

4587{
4588 // TODO: make the force parameter actually do something.
4589 // the header file says higher force causes more damage.
4590 // perhaps that is what it should do?
4591 tripoint tp = traj.front();
4592 if( !critter_at( tp ) ) {
4593 debugmsg( _( "Nothing at (%d,%d,%d) to knockback!" ), tp.x, tp.y, tp.z );
4594 return;
4595 }
4596 std::size_t force_remaining = traj.size();
4597 if( monster *const targ = critter_at<monster>( tp, true ) ) {
4598 if( stun > 0 ) {
4599 targ->add_effect( effect_stunned, 1_turns * stun );
4600 add_msg( _( "%s was stunned!" ), targ->name() );
4601 }
4602 for( size_t i = 1; i < traj.size(); i++ ) {
4603 if( m.impassable( traj[i].xy() ) ) {
4604 targ->setpos( traj[i - 1] );
4605 force_remaining = traj.size() - i;
4606 if( stun != 0 ) {
4607 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4608 add_msg( _( "%s was stunned!" ), targ->name() );
4609 add_msg( _( "%s slammed into an obstacle!" ), targ->name() );
4610 targ->apply_damage( nullptr, bodypart_id( "torso" ), dam_mult * force_remaining );
4611 targ->check_dead_state();
4612 }
4613 m.bash( traj[i], 2 * dam_mult * force_remaining );
4614 break;
4615 } else if( critter_at( traj[i] ) ) {
4616 targ->setpos( traj[i - 1] );
4617 force_remaining = traj.size() - i;
4618 if( stun != 0 ) {
4619 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4620 add_msg( _( "%s was stunned!" ), targ->name() );
4621 }
4622 traj.erase( traj.begin(), traj.begin() + i );
4623 if( critter_at<monster>( traj.front() ) ) {
4624 add_msg( _( "%s collided with something else and sent it flying!" ),
4625 targ->name() );
4626 } else if( npc *const guy = critter_at<npc>( traj.front() ) ) {
4627 if( guy->male ) {
4628 add_msg( _( "%s collided with someone else and sent him flying!" ),
4629 targ->name() );
4630 } else {
4631 add_msg( _( "%s collided with someone else and sent her flying!" ),
4632 targ->name() );
4633 }
4634 } else if( u.pos() == traj.front() ) {
4635 add_msg( m_bad, _( "%s collided with you and sent you flying!" ), targ->name() );
4636 }
4637 knockback( traj, stun, dam_mult );
4638 break;
4639 }
4640 targ->setpos( traj[i] );
4641 if( m.has_flag( "LIQUID", targ->pos() ) && !targ->can_drown() && !targ->is_dead() ) {
4642 targ->die( nullptr );
4643 if( u.sees( *targ ) ) {
4644 add_msg( _( "The %s drowns!" ), targ->name() );
4645 }
4646 }
4647 if( !m.has_flag( "LIQUID", targ->pos() ) && targ->has_flag( MF_AQUATIC ) &&
4648 !targ->is_dead() ) {
4649 targ->die( nullptr );
4650 if( u.sees( *targ ) ) {
4651 add_msg( _( "The %s flops around and dies!" ), targ->name() );
4652 }
4653 }
4654 }
4655 } else if( npc *const targ = critter_at<npc>( tp ) ) {
4656 if( stun > 0 ) {
4657 targ->add_effect( effect_stunned, 1_turns * stun );
4658 add_msg( _( "%s was stunned!" ), targ->name );
4659 }
4660 for( size_t i = 1; i < traj.size(); i++ ) {
4661 if( m.impassable( traj[i].xy() ) ) { // oops, we hit a wall!
4662 targ->setpos( traj[i - 1] );
4663 force_remaining = traj.size() - i;
4664 if( stun != 0 ) {
4665 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4666 if( targ->has_effect( effect_stunned ) ) {
4667 add_msg( _( "%s was stunned!" ), targ->name );
4668 }
4669
4670 std::array<bodypart_id, 8> bps = {{
4671 bodypart_id( "head" ),
4672 bodypart_id( "arm_l" ), bodypart_id( "arm_r" ),
4673 bodypart_id( "hand_l" ), bodypart_id( "hand_r" ),
4674 bodypart_id( "torso" ),
4675 bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
4676 }
4677 };
4678 for( const bodypart_id &bp : bps ) {
4679 if( one_in( 2 ) ) {
4680 targ->deal_damage( nullptr, bp, damage_instance( DT_BASH, force_remaining * dam_mult ) );
4681 }
4682 }
4683 targ->check_dead_state();
4684 }
4685 m.bash( traj[i], 2 * dam_mult * force_remaining );
4686 break;
4687 } else if( critter_at( traj[i] ) ) {
4688 targ->setpos( traj[i - 1] );
4689 force_remaining = traj.size() - i;
4690 if( stun != 0 ) {
4691 add_msg( _( "%s was stunned!" ), targ->name );
4692 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4693 }
4694 traj.erase( traj.begin(), traj.begin() + i );
4695 const tripoint &traj_front = traj.front();
4696 if( critter_at<monster>( traj_front ) ) {
4697 add_msg( _( "%s collided with something else and sent it flying!" ),
4698 targ->name );
4699 } else if( npc *const guy = critter_at<npc>( traj_front ) ) {
4700 if( guy->male ) {
4701 add_msg( _( "%s collided with someone else and sent him flying!" ),
4702 targ->name );
4703 } else {
4704 add_msg( _( "%s collided with someone else and sent her flying!" ),
4705 targ->name );
4706 }
4707 } else if( u.posx() == traj_front.x && u.posy() == traj_front.y &&
4709 ( u.footwear_factor() == .5 && one_in( 2 ) ) ) ) ) {
4710 add_msg( _( "%s collided with you, and barely dislodges your tentacles!" ), targ->name );
4711 } else if( u.posx() == traj_front.x && u.posy() == traj_front.y ) {
4712 add_msg( m_bad, _( "%s collided with you and sent you flying!" ), targ->name );
4713 }
4714 knockback( traj, stun, dam_mult );
4715 break;
4716 }
4717 targ->setpos( traj[i] );
4718 }
4719 } else if( u.pos() == tp ) {
4720 if( stun > 0 ) {
4721 u.add_effect( effect_stunned, 1_turns * stun );
4722 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4723 "You were stunned for %d turns!",
4724 stun ),
4725 stun );
4726 }
4727 for( size_t i = 1; i < traj.size(); i++ ) {
4728 if( m.impassable( traj[i] ) ) { // oops, we hit a wall!
4729 u.setpos( traj[i - 1] );
4730 force_remaining = traj.size() - i;
4731 if( stun != 0 ) {
4732 if( u.has_effect( effect_stunned ) ) {
4733 add_msg( m_bad, vgettext( "You were stunned AGAIN for %d turn!",
4734 "You were stunned AGAIN for %d turns!",
4735 force_remaining ),
4736 force_remaining );
4737 } else {
4738 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4739 "You were stunned for %d turns!",
4740 force_remaining ),
4741 force_remaining );
4742 }
4743 u.add_effect( effect_stunned, 1_turns * force_remaining );
4744 std::array<bodypart_id, 8> bps = {{
4745 bodypart_id( "head" ),
4746 bodypart_id( "arm_l" ), bodypart_id( "arm_r" ),
4747 bodypart_id( "hand_l" ), bodypart_id( "hand_r" ),
4748 bodypart_id( "torso" ),
4749 bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
4750 }
4751 };
4752 for( const bodypart_id &bp : bps ) {
4753 if( one_in( 2 ) ) {
4754 u.deal_damage( nullptr, bp, damage_instance( DT_BASH, force_remaining * dam_mult ) );
4755 }
4756 }
4758 }
4759 m.bash( traj[i], 2 * dam_mult * force_remaining );
4760 break;
4761 } else if( critter_at( traj[i] ) ) {
4762 u.setpos( traj[i - 1] );
4763 force_remaining = traj.size() - i;
4764 if( stun != 0 ) {
4765 if( u.has_effect( effect_stunned ) ) {
4766 add_msg( m_bad, vgettext( "You were stunned AGAIN for %d turn!",
4767 "You were stunned AGAIN for %d turns!",
4768 force_remaining ),
4769 force_remaining );
4770 } else {
4771 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4772 "You were stunned for %d turns!",
4773 force_remaining ),
4774 force_remaining );
4775 }
4776 u.add_effect( effect_stunned, 1_turns * force_remaining );
4777 }
4778 traj.erase( traj.begin(), traj.begin() + i );
4779 if( critter_at<monster>( traj.front() ) ) {
4780 add_msg( _( "You collided with something and sent it flying!" ) );
4781 } else if( npc *const guy = critter_at<npc>( traj.front() ) ) {
4782 if( guy->male ) {
4783 add_msg( _( "You collided with someone and sent him flying!" ) );
4784 } else {
4785 add_msg( _( "You collided with someone and sent her flying!" ) );
4786 }
4787 }
4788 knockback( traj, stun, dam_mult );
4789 break;
4790 }
4791 if( m.has_flag( "LIQUID", u.pos() ) && force_remaining == 0 ) {
4792 avatar_action::swim( m, u, u.pos() );
4793 } else {
4794 u.setpos( traj[i] );
4795 }
4796 }
4797 }
4798}
double footwear_factor() const
Returns 1 if the player is wearing something on both feet, .5 if on one, and 0 if on neither.
Definition: character.cpp:8767
dealt_damage_instance deal_damage(Creature *source, bodypart_id bp, const damage_instance &d) override
Calls Creature::deal_damage and handles damaged effects (waking up, etc.)
Definition: character.cpp:8293
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:974
@ DT_BASH
Definition: damage.h:24
static const trait_id trait_LEG_TENT_BRACE("LEG_TENT_BRACE")
static const efftype_id effect_stunned("stunned")
@ MF_AQUATIC
Definition: mtype.h:89
void swim(map &m, avatar &you, const tripoint &p)
Handles swimming by the player.
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, Creature::add_effect(), add_msg(), map::bash(), Creature::check_dead_state(), critter_at(), Character::deal_damage(), debugmsg, DT_BASH, effect_stunned, Character::footwear_factor(), Creature::has_effect(), map::has_flag(), Character::has_trait(), map::impassable(), knockback(), m, m_bad, MF_AQUATIC, one_in(), Character::pos(), Character::posx(), Character::posy(), Character::sees(), Character::setpos(), avatar_action::swim(), trait_LEG_TENT_BRACE, u, vgettext(), tripoint::x, tripoint::y, and tripoint::z.

◆ light_level()

unsigned char game::light_level ( int  zlev) const

Returns coarse number-of-squares of visibility at the current light level.

Used by monster and NPC AI.

Definition at line 3913 of file game.cpp.

3914{
3915 const float light = natural_light_level( zlev );
3916 return LIGHT_RANGE( light );
3917}
float natural_light_level(int zlev) const
Definition: game.cpp:3853
#define LIGHT_RANGE(b)
Definition: lightmap.h:41

References light, LIGHT_RANGE, and natural_light_level().

Referenced by calc_driving_offset(), and update_overmap_seen().

◆ list_active_characters()

std::vector< std::string > game::list_active_characters ( )

Returns a list of currently active character saves.

Definition at line 3120 of file game.cpp.

3121{
3122 std::vector<std::string> saves;
3123 for( auto &worldsave : world_generator->active_world->world_saves ) {
3124 saves.push_back( worldsave.player_name() );
3125 }
3126 return saves;
3127}

References world_generator.

Referenced by cleanup_at_end().

◆ list_items()

game::vmenu_ret game::list_items ( const std::vector< map_item_stack > &  item_list)
private

Definition at line 7524 of file game.cpp.

7525{
7526 std::vector<map_item_stack> ground_items = item_list;
7527 int iInfoHeight = 0;
7528 int iMaxRows = 0;
7529 int width = 0;
7530 int max_name_width = 0;
7531
7532 //find max length of item name and resize window width
7533 for( const map_item_stack &cur_item : ground_items ) {
7534 const int item_len = utf8_width( remove_color_tags( cur_item.example->display_name() ) ) + 15;
7535 if( item_len > max_name_width ) {
7536 max_name_width = item_len;
7537 }
7538 }
7539
7540 tripoint active_pos;
7541 map_item_stack *activeItem = nullptr;
7542
7543 catacurses::window w_items;
7544 catacurses::window w_items_border;
7545 catacurses::window w_item_info;
7546
7547 ui_adaptor ui;
7548 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
7549 iInfoHeight = std::min( 25, TERMY / 2 );
7550 iMaxRows = TERMY - iInfoHeight - 2;
7551
7552 width = clamp( max_name_width, 45, TERMX / 3 );
7553
7554 const int offsetX = TERMX - width;
7555
7556 w_items = catacurses::newwin( TERMY - 2 - iInfoHeight,
7557 width - 2, point( offsetX + 1, 1 ) );
7558 w_items_border = catacurses::newwin( TERMY - iInfoHeight,
7559 width, point( offsetX, 0 ) );
7560 w_item_info = catacurses::newwin( iInfoHeight, width,
7561 point( offsetX, TERMY - iInfoHeight ) );
7562
7563 if( activeItem ) {
7564 centerlistview( active_pos, width );
7565 }
7566
7567 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
7568 } );
7569 ui.mark_resize();
7570
7571 // use previously selected sorting method
7572 bool sort_radius = uistate.list_item_sort != 2;
7573 bool addcategory = !sort_radius;
7574
7575 // reload filter/priority settings on the first invocation, if they were active
7576 if( !uistate.list_item_init ) {
7579 }
7582 }
7585 }
7586 uistate.list_item_init = true;
7587 }
7588
7589 //this stores only those items that match our filter
7590 std::vector<map_item_stack> filtered_items =
7591 !sFilter.empty() ? filter_item_stacks( ground_items, sFilter ) : ground_items;
7592 int highPEnd = list_filter_high_priority( filtered_items, list_item_upvote );
7593 int lowPStart = list_filter_low_priority( filtered_items, highPEnd, list_item_downvote );
7594 int iItemNum = ground_items.size();
7595
7596 const tripoint stored_view_offset = u.view_offset;
7597
7599
7600 int iActive = 0; // Item index that we're looking at
7601 bool refilter = true;
7602 int page_num = 0;
7603 int iCatSortNum = 0;
7604 int iScrollPos = 0;
7605 std::map<int, std::string> mSortCategory;
7606
7607 std::string action;
7608 input_context ctxt( "LIST_ITEMS" );
7609 ctxt.register_action( "UP", to_translation( "Move cursor up" ) );
7610 ctxt.register_action( "DOWN", to_translation( "Move cursor down" ) );
7611 ctxt.register_action( "LEFT", to_translation( "Previous item" ) );
7612 ctxt.register_action( "RIGHT", to_translation( "Next item" ) );
7613 ctxt.register_action( "PAGE_DOWN" );
7614 ctxt.register_action( "PAGE_UP" );
7615 ctxt.register_action( "NEXT_TAB" );
7616 ctxt.register_action( "PREV_TAB" );
7617 ctxt.register_action( "HELP_KEYBINDINGS" );
7618 ctxt.register_action( "QUIT" );
7619 ctxt.register_action( "FILTER" );
7620 ctxt.register_action( "RESET_FILTER" );
7621 ctxt.register_action( "EXAMINE" );
7622 ctxt.register_action( "COMPARE" );
7623 ctxt.register_action( "PRIORITY_INCREASE" );
7624 ctxt.register_action( "PRIORITY_DECREASE" );
7625 ctxt.register_action( "SORT" );
7626 ctxt.register_action( "TRAVEL_TO" );
7627
7629
7630 ui.on_redraw( [&]( const ui_adaptor & ) {
7631 reset_item_list_state( w_items_border, iInfoHeight, sort_radius );
7632
7633 if( ground_items.empty() ) {
7634 wnoutrefresh( w_items_border );
7635 mvwprintz( w_items, point( 2, 10 ), c_white, _( "You don't see any items around you!" ) );
7636 } else {
7637 int iStartPos = 0;
7638 werase( w_items );
7639 calcStartPos( iStartPos, iActive, iMaxRows, iItemNum );
7640 int iNum = 0;
7641 bool high = false;
7642 bool low = false;
7643 int index = 0;
7644 int iCatSortOffset = 0;
7645
7646 for( int i = 0; i < iStartPos; i++ ) {
7647 if( !mSortCategory[i].empty() ) {
7648 iNum++;
7649 }
7650 }
7651 for( auto iter = filtered_items.begin(); iter != filtered_items.end(); ++index ) {
7652 if( highPEnd > 0 && index < highPEnd + iCatSortOffset ) {
7653 high = true;
7654 low = false;
7655 } else if( index >= lowPStart + iCatSortOffset ) {
7656 high = false;
7657 low = true;
7658 } else {
7659 high = false;
7660 low = false;
7661 }
7662
7663 if( iNum >= iStartPos && iNum < iStartPos + ( iMaxRows > iItemNum ? iItemNum : iMaxRows ) ) {
7664 int iThisPage = 0;
7665 if( !mSortCategory[iNum].empty() ) {
7666 iCatSortOffset++;
7667 mvwprintz( w_items, point( 1, iNum - iStartPos ), c_magenta, mSortCategory[iNum] );
7668 } else {
7669 if( iNum == iActive ) {
7670 iThisPage = page_num;
7671 }
7672 std::string sText;
7673 if( iter->vIG.size() > 1 ) {
7674 sText += string_format( "[%d/%d] (%d) ", iThisPage + 1, iter->vIG.size(), iter->totalcount );
7675 }
7676 sText += iter->example->tname();
7677 if( iter->vIG[iThisPage].count > 1 ) {
7678 sText += string_format( "[%d]", iter->vIG[iThisPage].count );
7679 }
7680
7681 nc_color col = c_light_green;
7682 if( iNum != iActive ) {
7683 if( high ) {
7684 col = c_yellow;
7685 } else if( low ) {
7686 col = c_red;
7687 } else {
7688 col = iter->example->color_in_inventory();
7689 }
7690 }
7691 trim_and_print( w_items, point( 1, iNum - iStartPos ), width - 9, col, sText );
7692 const int numw = iItemNum > 9 ? 2 : 1;
7693 const int x = iter->vIG[iThisPage].pos.x;
7694 const int y = iter->vIG[iThisPage].pos.y;
7695 mvwprintz( w_items, point( width - 6 - numw, iNum - iStartPos ),
7696 iNum == iActive ? c_light_green : c_light_gray,
7697 "%*d %s", numw, rl_dist( point_zero, point( x, y ) ),
7699 ++iter;
7700 }
7701 } else {
7702 ++iter;
7703 }
7704 iNum++;
7705 }
7706 iNum = 0;
7707 for( int i = 0; i < iActive; i++ ) {
7708 if( !mSortCategory[i].empty() ) {
7709 iNum++;
7710 }
7711 }
7712 mvwprintz( w_items_border, point( ( width - 9 ) / 2 + ( iItemNum > 9 ? 0 : 1 ), 0 ),
7713 c_light_green, " %*d", iItemNum > 9 ? 2 : 1, iItemNum > 0 ? iActive - iNum + 1 : 0 );
7714 wprintz( w_items_border, c_white, " / %*d ", iItemNum > 9 ? 2 : 1, iItemNum - iCatSortNum );
7715 werase( w_item_info );
7716
7717 if( iItemNum > 0 && activeItem ) {
7718 std::vector<iteminfo> vThisItem;
7719 std::vector<iteminfo> vDummy;
7720 activeItem->example->info( true, vThisItem );
7721
7722 item_info_data dummy( "", "", vThisItem, vDummy, iScrollPos );
7723 dummy.without_getch = true;
7724 dummy.without_border = true;
7725
7726 draw_item_info( w_item_info, dummy );
7727 }
7728 draw_scrollbar( w_items_border, iActive, iMaxRows, iItemNum, point_south );
7729 wnoutrefresh( w_items_border );
7730 }
7731
7732 const bool bDrawLeft = ground_items.empty() || filtered_items.empty() || !activeItem || filter_type;
7733 draw_custom_border( w_item_info, bDrawLeft, true, true, true, LINE_XXXO, LINE_XOXX, true, true );
7734
7735 if( iItemNum > 0 && activeItem ) {
7736 // print info window title: < item name >
7737 mvwprintw( w_item_info, point( 2, 0 ), "< " );
7738 trim_and_print( w_item_info, point( 4, 0 ), width - 8, activeItem->example->color_in_inventory(),
7739 activeItem->example->display_name() );
7740 wprintw( w_item_info, " >" );
7741 }
7742
7743 wnoutrefresh( w_items );
7744 wnoutrefresh( w_item_info );
7745
7746 if( filter_type ) {
7747 draw_item_filter_rules( w_item_info, 0, iInfoHeight - 1, filter_type.value() );
7748 }
7749 } );
7750
7751 cata::optional<tripoint> trail_start;
7752 cata::optional<tripoint> trail_end;
7753 bool trail_end_x = false;
7754 shared_ptr_fast<draw_callback_t> trail_cb = create_trail_callback( trail_start, trail_end,
7755 trail_end_x );
7756 add_draw_callback( trail_cb );
7757
7758 do {
7759 if( action == "COMPARE" && activeItem ) {
7760 game_menus::inv::compare( u, active_pos );
7761 } else if( action == "FILTER" ) {
7762 filter_type = item_filter_type::FILTER;
7763 ui.invalidate_ui();
7765 .title( _( "Filter:" ) )
7766 .width( 55 )
7767 .description( _( "UP: history, CTRL-U: clear line, ESC: abort, ENTER: save" ) )
7768 .identifier( "item_filter" )
7769 .max_length( 256 )
7770 .edit( sFilter );
7771 refilter = true;
7772 addcategory = !sort_radius;
7774 filter_type = cata::nullopt;
7775 } else if( action == "RESET_FILTER" ) {
7776 sFilter.clear();
7777 filtered_items = ground_items;
7778 refilter = true;
7780 addcategory = !sort_radius;
7781 } else if( action == "EXAMINE" && !filtered_items.empty() && activeItem ) {
7782 std::vector<iteminfo> vThisItem;
7783 std::vector<iteminfo> vDummy;
7784 activeItem->example->info( true, vThisItem );
7785
7786 item_info_data info_data( activeItem->example->tname(), activeItem->example->type_name(), vThisItem,
7787 vDummy );
7788 info_data.handle_scrolling = true;
7789
7791 return catacurses::newwin( TERMY, width - 5, point_zero );
7792 }, info_data );
7793 } else if( action == "PRIORITY_INCREASE" ) {
7794 filter_type = item_filter_type::HIGH_PRIORITY;
7795 ui.invalidate_ui();
7797 .title( _( "High Priority:" ) )
7798 .width( 55 )
7800 .description( _( "UP: history, CTRL-U clear line, ESC: abort, ENTER: save" ) )
7801 .identifier( "list_item_priority" )
7802 .max_length( 256 )
7803 .query_string();
7804 refilter = true;
7805 addcategory = !sort_radius;
7807 filter_type = cata::nullopt;
7808 } else if( action == "PRIORITY_DECREASE" ) {
7809 filter_type = item_filter_type::LOW_PRIORITY;
7810 ui.invalidate_ui();
7812 .title( _( "Low Priority:" ) )
7813 .width( 55 )
7815 .description( _( "UP: history, CTRL-U clear line, ESC: abort, ENTER: save" ) )
7816 .identifier( "list_item_downvote" )
7817 .max_length( 256 )
7818 .query_string();
7819 refilter = true;
7820 addcategory = !sort_radius;
7822 filter_type = cata::nullopt;
7823 } else if( action == "SORT" ) {
7824 if( sort_radius ) {
7825 sort_radius = false;
7826 addcategory = true;
7827 uistate.list_item_sort = 2; // list is sorted by category
7828 } else {
7829 sort_radius = true;
7830 uistate.list_item_sort = 1; // list is sorted by distance
7831 }
7832 highPEnd = -1;
7833 lowPStart = -1;
7834 iCatSortNum = 0;
7835
7836 mSortCategory.clear();
7837 refilter = true;
7838 } else if( action == "TRAVEL_TO" && activeItem ) {
7839 if( !u.sees( u.pos() + active_pos ) ) {
7840 add_msg( _( "You can't see that destination." ) );
7841 }
7842 auto route = m.route( u.pos(), u.pos() + active_pos, u.get_pathfinding_settings(),
7843 u.get_path_avoid() );
7844 if( route.size() > 1 ) {
7845 route.pop_back();
7846 u.set_destination( route );
7847 break;
7848 } else {
7849 add_msg( m_info, _( "You can't travel there." ) );
7850 }
7851 }
7852 if( uistate.list_item_sort == 1 ) {
7853 ground_items = item_list;
7854 } else if( uistate.list_item_sort == 2 ) {
7855 std::sort( ground_items.begin(), ground_items.end(), map_item_stack::map_item_stack_sort );
7856 }
7857
7858 if( refilter ) {
7859 refilter = false;
7860 filtered_items = filter_item_stacks( ground_items, sFilter );
7861 highPEnd = list_filter_high_priority( filtered_items, list_item_upvote );
7862 lowPStart = list_filter_low_priority( filtered_items, highPEnd, list_item_downvote );
7863 iActive = 0;
7864 page_num = 0;
7865 iItemNum = filtered_items.size();
7866 }
7867
7868 if( addcategory ) {
7869 addcategory = false;
7870 iCatSortNum = 0;
7871 mSortCategory.clear();
7872 if( highPEnd > 0 ) {
7873 mSortCategory[0] = _( "HIGH PRIORITY" );
7874 iCatSortNum++;
7875 }
7876 std::string last_cat_name;
7877 for( int i = std::max( 0, highPEnd );
7878 i < std::min( lowPStart, static_cast<int>( filtered_items.size() ) ); i++ ) {
7879 const std::string &cat_name = filtered_items[i].example->get_category().name();
7880 if( cat_name != last_cat_name ) {
7881 mSortCategory[i + iCatSortNum++] = cat_name;
7882 last_cat_name = cat_name;
7883 }
7884 }
7885 if( lowPStart < static_cast<int>( filtered_items.size() ) ) {
7886 mSortCategory[lowPStart + iCatSortNum++] = _( "LOW PRIORITY" );
7887 }
7888 if( !mSortCategory[0].empty() ) {
7889 iActive++;
7890 }
7891 iItemNum = static_cast<int>( filtered_items.size() ) + iCatSortNum;
7892 }
7893
7894 if( action == "UP" ) {
7895 do {
7896 iActive--;
7897
7898 } while( !mSortCategory[iActive].empty() );
7899 iScrollPos = 0;
7900 page_num = 0;
7901 if( iActive < 0 ) {
7902 iActive = iItemNum - 1;
7903 }
7904 } else if( action == "DOWN" ) {
7905 do {
7906 iActive++;
7907
7908 } while( !mSortCategory[iActive].empty() );
7909 iScrollPos = 0;
7910 page_num = 0;
7911 if( iActive >= iItemNum ) {
7912 iActive = mSortCategory[0].empty() ? 0 : 1;
7913 }
7914 } else if( action == "RIGHT" ) {
7915 if( !filtered_items.empty() && activeItem ) {
7916 if( ++page_num >= static_cast<int>( activeItem->vIG.size() ) ) {
7917 page_num = activeItem->vIG.size() - 1;
7918 }
7919 }
7920 } else if( action == "LEFT" ) {
7921 page_num = std::max( 0, page_num - 1 );
7922 } else if( action == "PAGE_UP" ) {
7923 iScrollPos--;
7924 } else if( action == "PAGE_DOWN" ) {
7925 iScrollPos++;
7926 } else if( action == "NEXT_TAB" || action == "PREV_TAB" ) {
7927 u.view_offset = stored_view_offset;
7929 }
7930
7931 active_pos = tripoint_zero;
7932 activeItem = nullptr;
7933
7934 if( mSortCategory[iActive].empty() ) {
7935 auto iter = filtered_items.begin();
7936 for( int iNum = 0; iter != filtered_items.end() && iNum < iActive; iNum++ ) {
7937 if( mSortCategory[iNum].empty() ) {
7938 ++iter;
7939 }
7940 }
7941 if( iter != filtered_items.end() ) {
7942 active_pos = iter->vIG[page_num].pos;
7943 activeItem = &( *iter );
7944 }
7945 }
7946
7947 if( activeItem ) {
7948 centerlistview( active_pos, width );
7949 trail_start = u.pos();
7950 trail_end = u.pos() + active_pos;
7951 // Actually accessed from the terrain overlay callback `trail_cb` in the
7952 // call to `ui_manager::redraw`.
7953 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
7954 trail_end_x = true;
7955 } else {
7956 u.view_offset = stored_view_offset;
7957 trail_start = trail_end = cata::nullopt;
7958 }
7960
7962
7963 action = ctxt.handle_input();
7964 } while( action != "QUIT" );
7965
7966 u.view_offset = stored_view_offset;
7967 return game::vmenu_ret::QUIT;
7968}
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:145
std::string list_item_upvote
Definition: game.h:1079
std::string list_item_downvote
Definition: game.h:1080
std::string sFilter
Definition: game.h:1078
void reset_item_list_state(const catacurses::window &window, int height, bool bRadiusSort)
Definition: game.cpp:7411
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4008
std::string display_name(unsigned int quantity=1) const
Returns the item name and the charges or contained charges (if the item can have charges at all).
Definition: item.cpp:4630
static bool map_item_stack_sort(const map_item_stack &lhs, const map_item_stack &rhs)
std::vector< item_group > vIG
const item * example
string_input_popup & identifier(const std::string &value)
An identifier to be used to store / get the input history.
string_input_popup & text(const std::string &value)
Set / get the text that can be modified by the user.
void edit(std::string &value)
Edit values in place.
string_input_popup & width(int value)
Width (in console cells) of the input field itself.
string_input_popup & description(const std::string &value)
Additional help text, shown below the input box.
string_input_popup & title(const std::string &value)
The title: short string before the actual input field.
std::string list_item_priority
Definition: uistate.h:117
int list_item_sort
Definition: uistate.h:114
bool list_item_downvote_active
Definition: uistate.h:120
bool list_item_init
Definition: uistate.h:122
bool list_item_filter_active
Definition: uistate.h:119
std::string list_item_filter
Definition: uistate.h:115
bool list_item_priority_active
Definition: uistate.h:121
std::string list_item_downvote
Definition: uistate.h:116
direction direction_from(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:540
static shared_ptr_fast< game::draw_callback_t > create_trail_callback(const cata::optional< tripoint > &trail_start, const cata::optional< tripoint > &trail_end, const bool &trail_end_x)
Definition: game.cpp:3433
uistatedata uistate
Definition: game.cpp:269
static void centerlistview(const tripoint &active_item_position, int ui_width)
Definition: game.cpp:7256
std::string direction_name_short(const direction dir)
Definition: line.cpp:533
int list_filter_high_priority(std::vector< map_item_stack > &stack, const std::string &priorities)
std::vector< map_item_stack > filter_item_stacks(const std::vector< map_item_stack > &stack, const std::string &filter)
int list_filter_low_priority(std::vector< map_item_stack > &stack, const int start, const std::string &priorities)
void mvwprintw(const window &win, const point &p, const std::string &text)
void wprintw(const window &win, const std::string &text)
void calcStartPos(int &iStartPos, const int iCurrentLine, const int iContentHeight, const int iNumEntries)
Definition: output.cpp:1507
void draw_item_filter_rules(const catacurses::window &win, int starty, int height, item_filter_type type)
Write some tips (such as precede items with - to exclude them) onto the window.
Definition: output.cpp:810
void draw_scrollbar(const catacurses::window &window, const int iCurrentLine, const int iContentHeight, const int iNumLines, const point &offset, nc_color bar_color, const bool bDoNotScrollToEnd)
Draw a scrollbar (Legacy function, use class scrollbar instead!)
Definition: output.cpp:1314
std::string remove_color_tags(const std::string &s)
Removes the color tags from the input string.
Definition: output.cpp:145
void draw_custom_border(const catacurses::window &w, const catacurses::chtype ls, const catacurses::chtype rs, const catacurses::chtype ts, const catacurses::chtype bs, const catacurses::chtype tl, const catacurses::chtype tr, const catacurses::chtype bl, const catacurses::chtype br, const nc_color FG, const point &pos, int height, int width)
Definition: output.cpp:524
void trim_and_print(const catacurses::window &w, const point &begin, const int width, const nc_color &base_color, const std::string &text, const report_color_error color_error)
Prints a single line of text.
Definition: output.cpp:214
#define LINE_XOXX
Definition: output.h:47
#define LINE_XXXO
Definition: output.h:45

References _, action, add_draw_callback(), add_msg(), c_light_gray, c_light_green, c_magenta, c_red, c_white, c_yellow, calcStartPos(), centerlistview(), CHANGE_TAB, clamp(), item::color_in_inventory(), game_menus::inv::compare(), create_trail_callback(), string_input_popup::description(), direction_from(), direction_name_short(), item::display_name(), draw_custom_border(), draw_item_filter_rules(), draw_item_info(), draw_scrollbar(), string_input_popup::edit(), map_item_stack::example, FILTER, filter_item_stacks(), Character::get_path_avoid(), Character::get_pathfinding_settings(), input_context::handle_input(), item_info_data::handle_scrolling, high, HIGH_PRIORITY, string_input_popup::identifier(), item::info(), invalidate_main_ui_adaptor(), LINE_XOXX, LINE_XXXO, list_filter_high_priority(), list_filter_low_priority(), list_item_downvote, uistatedata::list_item_downvote, uistatedata::list_item_downvote_active, uistatedata::list_item_filter, uistatedata::list_item_filter_active, uistatedata::list_item_init, uistatedata::list_item_priority, uistatedata::list_item_priority_active, uistatedata::list_item_sort, list_item_upvote, LOW_PRIORITY, m, m_info, map_item_stack::map_item_stack_sort(), string_input_popup::max_length(), catacurses::mvwprintw(), mvwprintz(), catacurses::newwin(), cata::nullopt, point_south, point_zero, Character::pos(), string_input_popup::query_string(), QUIT, ui_manager::redraw(), input_context::register_action(), remove_color_tags(), reset_item_list_state(), rl_dist(), map::route(), Character::sees(), Character::set_destination(), sFilter, string_format(), TERMX, TERMY, string_input_popup::text(), string_input_popup::title(), item::tname(), to_translation(), trim_and_print(), tripoint_zero, item::type_name(), u, uistate, utf8_width(), cata::optional< T >::value(), player::view_offset, map_item_stack::vIG, catacurses::werase(), string_input_popup::width(), item_info_data::without_border, item_info_data::without_getch, catacurses::wnoutrefresh(), catacurses::wprintw(), and wprintz().

Referenced by list_items_monsters().

◆ list_items_monsters()

void game::list_items_monsters ( )
private

Definition at line 7479 of file game.cpp.

7480{
7481 std::vector<Creature *> mons = u.get_visible_creatures( current_daylight_level( calendar::turn ) );
7482 // whole reality bubble
7483 const std::vector<map_item_stack> items = find_nearby_items( 60 );
7484
7485 if( mons.empty() && items.empty() ) {
7486 add_msg( m_info, _( "You don't see any items or monsters around you!" ) );
7487 return;
7488 }
7489
7490 std::sort( mons.begin(), mons.end(), [&]( const Creature * lhs, const Creature * rhs ) {
7491 const auto att_lhs = lhs->attitude_to( u );
7492 const auto att_rhs = rhs->attitude_to( u );
7493
7494 return att_lhs < att_rhs || ( att_lhs == att_rhs
7495 && rl_dist( u.pos(), lhs->pos() ) < rl_dist( u.pos(), rhs->pos() ) );
7496 } );
7497
7498 // If the current list is empty, switch to the non-empty list
7500 if( items.empty() ) {
7501 uistate.vmenu_show_items = false;
7502 }
7503 } else if( mons.empty() ) {
7505 }
7506
7509 while( true ) {
7510 ret = uistate.vmenu_show_items ? list_items( items ) : list_monsters( mons );
7513 } else {
7514 break;
7515 }
7516 }
7517
7518 if( ret == game::vmenu_ret::FIRE ) {
7520 }
7522}
double current_daylight_level(const time_point &p)
Returns the current seasonally-adjusted maximum daylight level.
Definition: calendar.cpp:171
game::vmenu_ret list_monsters(const std::vector< Creature * > &monster_list)
Definition: game.cpp:7970
game::vmenu_ret list_items(const std::vector< map_item_stack > &item_list)
Definition: game.cpp:7524
vmenu_ret
Definition: game.h:805
std::vector< map_item_stack > find_nearby_items(int iRadius)
Definition: game.cpp:7185
void temp_exit_fullscreen()
Definition: game.cpp:535
void reenter_fullscreen()
Definition: game.cpp:545
bool vmenu_show_items
Definition: uistate.h:118

References _, add_msg(), CHANGE_TAB, current_daylight_level(), find_nearby_items(), FIRE, avatar_action::fire_wielded_weapon(), Character::get_visible_creatures(), list_items(), list_monsters(), m_info, reenter_fullscreen(), cata::hash64_detail::ret, temp_exit_fullscreen(), calendar::turn, u, uistate, and uistatedata::vmenu_show_items.

Referenced by handle_action(), and look_around().

◆ list_missions()

void game::list_missions ( )

Definition at line 22 of file mission_ui.cpp.

23{
24 catacurses::window w_missions;
25
26 enum class tab_mode : int {
27 TAB_ACTIVE = 0,
28 TAB_COMPLETED,
29 TAB_FAILED,
30 NUM_TABS,
31 FIRST_TAB = 0,
32 LAST_TAB = NUM_TABS - 1
33 };
34 tab_mode tab = tab_mode::FIRST_TAB;
35 size_t selection = 0;
36 int entries_per_page = 0;
37 input_context ctxt( "MISSIONS" );
38 ctxt.register_cardinal();
39 ctxt.register_action( "CONFIRM" );
40 ctxt.register_action( "QUIT" );
41 ctxt.register_action( "HELP_KEYBINDINGS" );
42
44 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
46
47 // content ranges from y=3 to FULL_SCREEN_HEIGHT - 2
48 entries_per_page = FULL_SCREEN_HEIGHT - 4;
49
50 ui.position_from_window( w_missions );
51 } );
52 ui.mark_resize();
53
54 std::vector<mission *> umissions;
55
56 ui.on_redraw( [&]( const ui_adaptor & ) {
57 werase( w_missions );
58 // entries_per_page * page number
59 const int top_of_page = entries_per_page * ( selection / entries_per_page );
60 const int bottom_of_page =
61 std::min( top_of_page + entries_per_page - 1, static_cast<int>( umissions.size() ) - 1 );
62
63 for( int i = 3; i < FULL_SCREEN_HEIGHT - 1; i++ ) {
64 mvwputch( w_missions, point( 30, i ), BORDER_COLOR, LINE_XOXO );
65 }
66
67 const std::vector<std::pair<tab_mode, std::string>> tabs = {
68 { tab_mode::TAB_ACTIVE, _( "ACTIVE MISSIONS" ) },
69 { tab_mode::TAB_COMPLETED, _( "COMPLETED MISSIONS" ) },
70 { tab_mode::TAB_FAILED, _( "FAILED MISSIONS" ) },
71 };
72 draw_tabs( w_missions, tabs, tab );
73 draw_border_below_tabs( w_missions );
74
75 mvwputch( w_missions, point( 30, 2 ), BORDER_COLOR,
76 tab == tab_mode::TAB_COMPLETED ? ' ' : LINE_OXXX ); // ^|^
77 mvwputch( w_missions, point( 30, FULL_SCREEN_HEIGHT - 1 ), BORDER_COLOR, LINE_XXOX ); // _|_
78
79 draw_scrollbar( w_missions, selection, entries_per_page, umissions.size(), point( 0, 3 ) );
80
81 for( int i = top_of_page; i <= bottom_of_page; i++ ) {
82 const auto miss = umissions[i];
83 const nc_color col = u.get_active_mission() == miss ? c_light_green : c_white;
84 const int y = i - top_of_page + 3;
85 trim_and_print( w_missions, point( 1, y ), 28,
86 static_cast<int>( selection ) == i ? hilite( col ) : col,
87 miss->name() );
88 }
89
90 if( selection < umissions.size() ) {
91 const auto miss = umissions[selection];
92 const nc_color col = u.get_active_mission() == miss ? c_light_green : c_white;
93 std::string for_npc;
94 if( miss->get_npc_id().is_valid() ) {
95 npc *guy = g->find_npc( miss->get_npc_id() );
96 if( guy ) {
97 for_npc = string_format( _( " for %s" ), guy->disp_name() );
98 }
99 }
100
101 int y = 3;
102 y += fold_and_print( w_missions, point( 31, y ), getmaxx( w_missions ) - 33, col,
103 miss->name() + for_npc );
104
105 auto format_tokenized_description = []( const std::string & description,
106 const std::vector<std::pair<int, itype_id>> &rewards ) {
107 std::string formatted_description = description;
108 for( const auto &reward : rewards ) {
109 std::string token = "<reward_count:" + reward.second.str() + ">";
110 formatted_description = replace_all( formatted_description, token,
111 string_format( "%d", reward.first ) );
112 }
113 return formatted_description;
114 };
115
116 y++;
117 if( !miss->get_description().empty() ) {
118 y += fold_and_print( w_missions, point( 31, y ), getmaxx( w_missions ) - 33, c_white,
119 format_tokenized_description( miss->get_description(), miss->get_likely_rewards() ) );
120 }
121 if( miss->has_deadline() ) {
122 const time_point deadline = miss->get_deadline();
123 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Deadline: %s" ), to_string( deadline ) );
124
125 if( tab != tab_mode::TAB_COMPLETED ) {
126 // There's no point in displaying this for a completed mission.
127 // @ TODO: But displaying when you completed it would be useful.
128 const time_duration remaining = deadline - calendar::turn;
129 std::string remaining_time;
130
131 if( remaining <= 0_turns ) {
132 remaining_time = _( "None!" );
133 } else if( u.has_watch() ) {
134 remaining_time = to_string( remaining );
135 } else {
136 remaining_time = to_string_approx( remaining );
137 }
138
139 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Time remaining: %s" ), remaining_time );
140 }
141 }
142 if( miss->has_target() ) {
144 // TODO: target does not contain a z-component, targets are assumed to be on z=0
145 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Target: %s You: %s" ),
146 miss->get_target().to_string(), pos.to_string() );
147 }
148 } else {
149 static const std::map< tab_mode, std::string > nope = {
150 { tab_mode::TAB_ACTIVE, translate_marker( "You have no active missions!" ) },
151 { tab_mode::TAB_COMPLETED, translate_marker( "You haven't completed any missions!" ) },
152 { tab_mode::TAB_FAILED, translate_marker( "You haven't failed any missions!" ) }
153 };
154 mvwprintz( w_missions, point( 31, 4 ), c_light_red, _( nope.at( tab ) ) );
155 }
156
157 wnoutrefresh( w_missions );
158 } );
159
160 while( true ) {
161 umissions.clear();
162 if( tab < tab_mode::FIRST_TAB || tab >= tab_mode::NUM_TABS ) {
163 debugmsg( "The sanity check failed because tab=%d", static_cast<int>( tab ) );
164 tab = tab_mode::FIRST_TAB;
165 }
166 switch( tab ) {
168 umissions = u.get_active_missions();
169 break;
170 case tab_mode::TAB_COMPLETED:
171 umissions = u.get_completed_missions();
172 break;
173 case tab_mode::TAB_FAILED:
174 umissions = u.get_failed_missions();
175 break;
176 default:
177 break;
178 }
179 if( ( !umissions.empty() && selection >= umissions.size() ) ||
180 ( umissions.empty() && selection != 0 ) ) {
181 debugmsg( "Sanity check failed: selection=%d, size=%d", static_cast<int>( selection ),
182 static_cast<int>( umissions.size() ) );
183 selection = 0;
184 }
186 const std::string action = ctxt.handle_input();
187 if( action == "RIGHT" ) {
188 tab = static_cast<tab_mode>( static_cast<int>( tab ) + 1 );
189 if( tab >= tab_mode::NUM_TABS ) {
190 tab = tab_mode::FIRST_TAB;
191 }
192 selection = 0;
193 } else if( action == "LEFT" ) {
194 tab = static_cast<tab_mode>( static_cast<int>( tab ) - 1 );
195 if( tab < tab_mode::FIRST_TAB ) {
196 tab = tab_mode::LAST_TAB;
197 }
198 selection = 0;
199 } else if( action == "DOWN" ) {
200 selection++;
201 if( selection >= umissions.size() ) {
202 selection = 0;
203 }
204 } else if( action == "UP" ) {
205 if( selection == 0 ) {
206 selection = umissions.empty() ? 0 : umissions.size() - 1;
207 } else {
208 selection--;
209 }
210 } else if( action == "CONFIRM" ) {
211 if( tab == tab_mode::TAB_ACTIVE && selection < umissions.size() ) {
212 u.set_active_mission( *umissions[selection] );
213 }
214 break;
215 } else if( action == "QUIT" ) {
216 break;
217 }
218 }
219}
std::string to_string_approx(const time_duration &dur, const bool verbose)
Returns approximate duration.
Definition: calendar.cpp:361
bool has_watch() const
Returns true if the player or their vehicle has a watch.
Definition: character.cpp:831
void set_active_mission(mission &cur_mission)
Set which mission is active.
Definition: avatar.cpp:204
mission * get_active_mission() const
Returns the mission that is currently active.
Definition: avatar.cpp:183
std::vector< mission * > get_completed_missions() const
Definition: avatar.cpp:173
std::vector< mission * > get_active_missions() const
Definition: avatar.cpp:168
std::vector< mission * > get_failed_missions() const
Definition: avatar.cpp:178
A point in the game time.
Definition: calendar.h:431
nc_color hilite(const nc_color &c)
Definition: color.cpp:509
void draw_tabs(const catacurses::window &w, const std::vector< std::string > &tab_texts, size_t current_tab)
Definition: output.cpp:1274
void draw_border_below_tabs(const catacurses::window &w, nc_color border_color)
Definition: output.cpp:587
int fold_and_print(const catacurses::window &w, const point &begin, int width, const nc_color &base_color, const std::string &text, const char split)
Fold and print text in the given window.
Definition: output.cpp:299
#define LINE_XXOX
Definition: output.h:46
std::string replace_all(std::string input, const std::string &what, const std::string &with)
Replace all occurences of 'what' within 'input' with 'with'.
#define translate_marker(x)
Marks a string literal to be extracted for translation.
Definition: translations.h:30
catacurses::window new_centered_win(int nlines, int ncols)
Definition: ui.cpp:30

References _, action, BORDER_COLOR, c_light_green, c_light_red, c_white, debugmsg, Character::disp_name(), draw_border_below_tabs(), draw_scrollbar(), draw_tabs(), fold_and_print(), FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, g, avatar::get_active_mission(), avatar::get_active_missions(), avatar::get_completed_missions(), avatar::get_failed_missions(), catacurses::getmaxx(), Character::global_omt_location(), input_context::handle_input(), Character::has_watch(), hilite(), LINE_OXXX, LINE_XOXO, LINE_XXOX, mvwprintz(), mvwputch(), new_centered_win(), ui_manager::redraw(), input_context::register_action(), input_context::register_cardinal(), replace_all(), avatar::set_active_mission(), string_format(), anonymous_namespace{bionics_ui.cpp}::TAB_ACTIVE, coords::coord_point< Point, Origin, Scale >::to_string(), to_string(), to_string_approx(), translate_marker, trim_and_print(), calendar::turn, u, catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by handle_action().

◆ list_monsters()

game::vmenu_ret game::list_monsters ( const std::vector< Creature * > &  monster_list)
private

Definition at line 7970 of file game.cpp.

7971{
7972 const int iInfoHeight = 15;
7973 const int width = 45;
7974 int offsetX = 0;
7975 int iMaxRows = 0;
7976
7977 catacurses::window w_monsters;
7978 catacurses::window w_monsters_border;
7979 catacurses::window w_monster_info;
7980 catacurses::window w_monster_info_border;
7981
7982 Creature *cCurMon = nullptr;
7983 tripoint iActivePos;
7984
7985 bool hide_ui = false;
7986
7987 ui_adaptor ui;
7988 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
7989 if( hide_ui ) {
7990 ui.position( point_zero, point_zero );
7991 } else {
7992 offsetX = TERMX - width;
7993 iMaxRows = TERMY - iInfoHeight - 1;
7994
7995 w_monsters = catacurses::newwin( iMaxRows, width - 2, point( offsetX + 1,
7996 1 ) );
7997 w_monsters_border = catacurses::newwin( iMaxRows + 1, width, point( offsetX,
7998 0 ) );
7999 w_monster_info = catacurses::newwin( iInfoHeight - 2, width - 2,
8000 point( offsetX + 1, TERMY - iInfoHeight + 1 ) );
8001 w_monster_info_border = catacurses::newwin( iInfoHeight, width, point( offsetX,
8002 TERMY - iInfoHeight ) );
8003
8004 if( cCurMon ) {
8005 centerlistview( iActivePos, width );
8006 }
8007
8008 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
8009 }
8010 } );
8011 ui.mark_resize();
8012
8013 const int max_gun_range = u.weapon.gun_range( &u );
8014
8015 const tripoint stored_view_offset = u.view_offset;
8017
8018 int iActive = 0; // monster index that we're looking at
8019
8020 std::string action;
8021 input_context ctxt( "LIST_MONSTERS" );
8022 ctxt.register_action( "UP", to_translation( "Move cursor up" ) );
8023 ctxt.register_action( "DOWN", to_translation( "Move cursor down" ) );
8024 ctxt.register_action( "NEXT_TAB" );
8025 ctxt.register_action( "PREV_TAB" );
8026 ctxt.register_action( "SAFEMODE_BLACKLIST_ADD" );
8027 ctxt.register_action( "SAFEMODE_BLACKLIST_REMOVE" );
8028 ctxt.register_action( "QUIT" );
8029 if( bVMonsterLookFire ) {
8030 ctxt.register_action( "look" );
8031 ctxt.register_action( "fire" );
8032 }
8033 ctxt.register_action( "HELP_KEYBINDINGS" );
8034
8035 // first integer is the row the attitude category string is printed in the menu
8036 std::map<int, Creature::Attitude> mSortCategory;
8037
8038 for( int i = 0, last_attitude = -1; i < static_cast<int>( monster_list.size() ); i++ ) {
8039 const auto attitude = monster_list[i]->attitude_to( u );
8040 if( attitude != last_attitude ) {
8041 mSortCategory[i + mSortCategory.size()] = attitude;
8042 last_attitude = attitude;
8043 }
8044 }
8045
8046 ui.on_redraw( [&]( const ui_adaptor & ) {
8047 if( !hide_ui ) {
8048 draw_custom_border( w_monsters_border, true, true, true, true, true, true, LINE_XOXO, LINE_XOXO );
8049 draw_custom_border( w_monster_info_border, true, true, true, true, LINE_XXXO, LINE_XOXX, true,
8050 true );
8051
8052 mvwprintz( w_monsters_border, point( 2, 0 ), c_light_green, "<Tab> " );
8053 wprintz( w_monsters_border, c_white, _( "Monsters" ) );
8054
8055 if( monster_list.empty() ) {
8056 werase( w_monsters );
8057 mvwprintz( w_monsters, point( 2, iMaxRows / 3 ), c_white,
8058 _( "You don't see any monsters around you!" ) );
8059 } else {
8060 werase( w_monsters );
8061
8062 const int iNumMonster = monster_list.size();
8063 const int iMenuSize = monster_list.size() + mSortCategory.size();
8064
8065 const int numw = iNumMonster > 999 ? 4 :
8066 iNumMonster > 99 ? 3 :
8067 iNumMonster > 9 ? 2 : 1;
8068
8069 // given the currently selected monster iActive. get the selected row
8070 int iSelPos = iActive;
8071 for( auto &ia : mSortCategory ) {
8072 int index = ia.first;
8073 if( index <= iSelPos ) {
8074 ++iSelPos;
8075 } else {
8076 break;
8077 }
8078 }
8079 int iStartPos = 0;
8080 // use selected row get the start row
8081 calcStartPos( iStartPos, iSelPos, iMaxRows - 1, iMenuSize );
8082
8083 // get first visible monster and category
8084 int iCurMon = iStartPos;
8085 auto CatSortIter = mSortCategory.cbegin();
8086 while( CatSortIter != mSortCategory.cend() && CatSortIter->first < iStartPos ) {
8087 ++CatSortIter;
8088 --iCurMon;
8089 }
8090
8091 const auto endY = std::min<int>( iMaxRows - 1, iMenuSize );
8092 for( int y = 0; y < endY; ++y ) {
8093 if( CatSortIter != mSortCategory.cend() ) {
8094 const int iCurPos = iStartPos + y;
8095 const int iCatPos = CatSortIter->first;
8096 if( iCurPos == iCatPos ) {
8097 const std::string cat_name = Creature::get_attitude_ui_data(
8098 CatSortIter->second ).first.translated();
8099 mvwprintz( w_monsters, point( 1, y ), c_magenta, cat_name );
8100 ++CatSortIter;
8101 continue;
8102 }
8103 }
8104 // select current monster
8105 const auto critter = monster_list[iCurMon];
8106 const bool selected = iCurMon == iActive;
8107 ++iCurMon;
8108 if( critter->sees( g->u ) ) {
8109 mvwprintz( w_monsters, point( 0, y ), c_yellow, "!" );
8110 }
8111 bool is_npc = false;
8112 const monster *m = dynamic_cast<monster *>( critter );
8113 const npc *p = dynamic_cast<npc *>( critter );
8114 nc_color name_color = critter->basic_symbol_color();
8115
8116 if( selected ) {
8117 name_color = hilite( name_color );
8118 }
8119
8120 if( m != nullptr ) {
8121 trim_and_print( w_monsters, point( 1, y ), width - 26, name_color, m->name() );
8122 } else {
8123 trim_and_print( w_monsters, point( 1, y ), width - 26, name_color, critter->disp_name() );
8124 is_npc = true;
8125 }
8126
8127 if( selected && !get_safemode().empty() ) {
8128 const std::string monName = is_npc ? get_safemode().npc_type_name() : m->name();
8129
8130 std::string sSafemode;
8131 if( get_safemode().has_rule( monName, Creature::A_ANY ) ) {
8132 sSafemode = _( "<R>emove from safemode Blacklist" );
8133 } else {
8134 sSafemode = _( "<A>dd to safemode Blacklist" );
8135 }
8136
8137 shortcut_print( w_monsters, point( 2, getmaxy( w_monsters ) - 1 ),
8138 c_white, c_light_green, sSafemode );
8139 }
8140
8142 std::string sText;
8143
8144 if( m != nullptr ) {
8145 m->get_HP_Bar( color, sText );
8146 } else {
8147 std::tie( sText, color ) =
8148 ::get_hp_bar( critter->get_hp(), critter->get_hp_max(), false );
8149 }
8150 mvwprintz( w_monsters, point( width - 25, y ), color, sText );
8151
8152 if( m != nullptr ) {
8153 const auto att = m->get_attitude();
8154 sText = att.first;
8155 color = att.second;
8156 } else if( p != nullptr ) {
8157 sText = npc_attitude_name( p->get_attitude() );
8158 color = p->symbol_color();
8159 }
8160 mvwprintz( w_monsters, point( width - 19, y ), color, sText );
8161
8162 const int mon_dist = rl_dist( u.pos(), critter->pos() );
8163 const int numd = mon_dist > 999 ? 4 :
8164 mon_dist > 99 ? 3 :
8165 mon_dist > 9 ? 2 : 1;
8166
8167 trim_and_print( w_monsters, point( width - ( 8 + numd ), y ), 6 + numd,
8168 selected ? c_light_green : c_light_gray,
8169 "%*d %s",
8170 numd, mon_dist,
8171 direction_name_short( direction_from( u.pos(), critter->pos() ) ) );
8172 }
8173
8174 mvwprintz( w_monsters_border, point( ( width / 2 ) - numw - 2, 0 ), c_light_green, " %*d", numw,
8175 iActive + 1 );
8176 wprintz( w_monsters_border, c_white, " / %*d ", numw, static_cast<int>( monster_list.size() ) );
8177
8178 werase( w_monster_info );
8179 if( cCurMon ) {
8180 cCurMon->print_info( w_monster_info, 1, iInfoHeight - 3, 1 );
8181 }
8182
8183 draw_custom_border( w_monster_info_border, true, true, true, true, LINE_XXXO, LINE_XOXX, true,
8184 true );
8185
8186 if( bVMonsterLookFire ) {
8187 mvwprintw( w_monster_info_border, point_east, "< " );
8188 wprintz( w_monster_info_border, c_light_green, ctxt.press_x( "look" ) );
8189 wprintz( w_monster_info_border, c_light_gray, " %s", _( "to look around" ) );
8190
8191 if( cCurMon && rl_dist( u.pos(), cCurMon->pos() ) <= max_gun_range ) {
8192 wprintw( w_monster_info_border, " " );
8193 wprintz( w_monster_info_border, c_light_green, ctxt.press_x( "fire" ) );
8194 wprintz( w_monster_info_border, c_light_gray, " %s", _( "to shoot" ) );
8195 }
8196 wprintw( w_monster_info_border, " >" );
8197 }
8198
8199 draw_scrollbar( w_monsters_border, iActive, iMaxRows, static_cast<int>( monster_list.size() ),
8200 point_south );
8201 }
8202
8203 wnoutrefresh( w_monsters_border );
8204 wnoutrefresh( w_monster_info_border );
8205 wnoutrefresh( w_monsters );
8206 wnoutrefresh( w_monster_info );
8207 }
8208 } );
8209
8210 cata::optional<tripoint> trail_start;
8211 cata::optional<tripoint> trail_end;
8212 bool trail_end_x = false;
8213 shared_ptr_fast<draw_callback_t> trail_cb = create_trail_callback( trail_start, trail_end,
8214 trail_end_x );
8215 add_draw_callback( trail_cb );
8216
8217 do {
8218 if( action == "UP" ) {
8219 iActive--;
8220 if( iActive < 0 ) {
8221 if( monster_list.empty() ) {
8222 iActive = 0;
8223 } else {
8224 iActive = static_cast<int>( monster_list.size() ) - 1;
8225 }
8226 }
8227 } else if( action == "DOWN" ) {
8228 iActive++;
8229 if( iActive >= static_cast<int>( monster_list.size() ) ) {
8230 iActive = 0;
8231 }
8232 } else if( action == "NEXT_TAB" || action == "PREV_TAB" ) {
8233 u.view_offset = stored_view_offset;
8235 } else if( action == "SAFEMODE_BLACKLIST_REMOVE" ) {
8236 const auto m = dynamic_cast<monster *>( cCurMon );
8237 const std::string monName = ( m != nullptr ) ? m->name() : "human";
8238
8239 if( get_safemode().has_rule( monName, Creature::A_ANY ) ) {
8241 }
8242 } else if( action == "SAFEMODE_BLACKLIST_ADD" ) {
8243 if( !get_safemode().empty() ) {
8244 const auto m = dynamic_cast<monster *>( cCurMon );
8245 const std::string monName = ( m != nullptr ) ? m->name() : "human";
8246
8247 get_safemode().add_rule( monName, Creature::A_ANY, get_option<int>( "SAFEMODEPROXIMITY" ),
8249 }
8250 } else if( action == "look" ) {
8251 hide_ui = true;
8252 ui.mark_resize();
8253 look_around();
8254 hide_ui = false;
8255 ui.mark_resize();
8256 } else if( action == "fire" ) {
8257 if( cCurMon != nullptr && rl_dist( u.pos(), cCurMon->pos() ) <= max_gun_range ) {
8258 u.last_target = shared_from( *cCurMon );
8260 u.view_offset = stored_view_offset;
8261 return game::vmenu_ret::FIRE;
8262 }
8263 }
8264
8265 if( iActive >= 0 && static_cast<size_t>( iActive ) < monster_list.size() ) {
8266 cCurMon = monster_list[iActive];
8267 iActivePos = cCurMon->pos() - u.pos();
8268 centerlistview( iActivePos, width );
8269 trail_start = u.pos();
8270 trail_end = cCurMon->pos();
8271 // Actually accessed from the terrain overlay callback `trail_cb` in the
8272 // call to `ui_manager::redraw`.
8273 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
8274 trail_end_x = false;
8275 } else {
8276 cCurMon = nullptr;
8277 iActivePos = tripoint_zero;
8278 u.view_offset = stored_view_offset;
8279 trail_start = trail_end = cata::nullopt;
8280 }
8282
8284
8285 action = ctxt.handle_input();
8286 } while( action != "QUIT" );
8287
8288 u.view_offset = stored_view_offset;
8289
8290 return game::vmenu_ret::QUIT;
8291}
double recoil
Definition: character.h:618
nc_color symbol_color() const override
Color's character's tile's background.
Definition: character.cpp:5981
static const std::pair< translation, nc_color > & get_attitude_ui_data(Attitude att)
Creature Attitude as String and color.
Definition: creature.cpp:1854
virtual const tripoint & pos() const =0
virtual int print_info(const catacurses::window &w, int vStart, int vLines, int column) const =0
Write information about this creature.
shared_ptr_fast< T > shared_from(const T &critter)
Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature).
Definition: game.cpp:4880
bool bVMonsterLookFire
Definition: game.h:1083
int gun_range(const player *p) const
The weapons range in map squares.
Definition: item.cpp:7120
npc_attitude get_attitude() const
Definition: npc.cpp:3136
weak_ptr_fast< Creature > last_target
Definition: player.h:689
bool has_rule(const std::string &rule_in, Creature::Attitude attitude_in)
void remove_rule(const std::string &rule_in, Creature::Attitude attitude_in)
static nc_color color(const T_t &t)
@ RULE_BLACKLISTED
Definition: enums.h:54
constexpr double MAX_RECOIL
std::string npc_attitude_name(npc_attitude att)
Definition: npc.cpp:2542
std::pair< std::string, nc_color > get_hp_bar(const int cur_hp, const int max_hp, const bool is_mon)
Definition: output.cpp:1604
size_t shortcut_print(const catacurses::window &w, const point &p, nc_color text_color, nc_color shortcut_color, const std::string &fmt)
Definition: output.cpp:1543

References _, Creature::A_ANY, action, add_draw_callback(), safemode::add_rule(), bVMonsterLookFire, c_light_gray, c_light_green, c_magenta, c_white, c_yellow, calcStartPos(), centerlistview(), CHANGE_TAB, color(), create_trail_callback(), direction_from(), direction_name_short(), draw_custom_border(), draw_scrollbar(), FIRE, g, npc::get_attitude(), Creature::get_attitude_ui_data(), get_hp_bar(), get_safemode(), catacurses::getmaxy(), item::gun_range(), input_context::handle_input(), safemode::has_rule(), hilite(), invalidate_main_ui_adaptor(), player::last_target, LINE_XOXO, LINE_XOXX, LINE_XXXO, look_around(), m, MAX_RECOIL, catacurses::mvwprintw(), mvwprintz(), map::name(), catacurses::newwin(), npc_attitude_name(), safemode::npc_type_name(), cata::nullopt, point_east, point_south, point_zero, Creature::pos(), Character::pos(), input_context::press_x(), Creature::print_info(), QUIT, Character::recoil, ui_manager::redraw(), input_context::register_action(), safemode::remove_rule(), rl_dist(), RULE_BLACKLISTED, shared_from(), shortcut_print(), Character::symbol_color(), TERMX, TERMY, to_translation(), trim_and_print(), tripoint_zero, u, player::view_offset, Character::weapon, catacurses::werase(), catacurses::wnoutrefresh(), catacurses::wprintw(), and wprintz().

Referenced by list_items_monsters().

◆ load() [1/2]

bool game::load ( const save_t name)
private

Definition at line 2841 of file game.cpp.

2842{
2845 popup.message( "%s", _( "Please wait…\nLoading the save…" ) );
2848
2849 using namespace std::placeholders;
2850
2851 const std::string worldpath = get_world_base_save_path() + "/";
2852 const std::string playerpath = worldpath + name.base_path();
2853
2854 // Now load up the master game data; factions (and more?)
2855 load_master();
2856 u = avatar();
2857 u.name = name.player_name();
2858 // This should be initialized more globally (in player/Character constructor)
2860 if( !read_from_file( playerpath + SAVE_EXTENSION, std::bind( &game::unserialize, this, _1 ) ) ) {
2861 return false;
2862 }
2863
2865
2867
2868 read_from_file_optional( worldpath + name.base_path() + SAVE_EXTENSION_LOG,
2869 std::bind( &memorial_logger::load, &memorial(), _1 ) );
2870
2871#if defined(__ANDROID__)
2872 read_from_file_optional( worldpath + name.base_path() + SAVE_EXTENSION_SHORTCUTS,
2873 std::bind( &game::load_shortcuts, this, _1 ) );
2874#endif
2875
2876 // Now that the player's worn items are updated, their sight limits need to be
2877 // recalculated. (This would be cleaner if u.worn were private.)
2879
2880 if( !gamemode ) {
2881 gamemode = std::make_unique<special_game>();
2882 }
2883
2884 safe_mode = get_option<bool>( "SAFEMODE" ) ? SAFE_MODE_ON : SAFE_MODE_OFF;
2885 mostseen = 0; // ...and mostseen is 0, we haven't seen any monsters yet.
2886
2887 init_autosave();
2888 get_auto_pickup().load_character(); // Load character auto pickup rules
2889 get_auto_notes_settings().load(); // Load character auto notes settings
2890 get_safemode().load_character(); // Load character safemode rules
2891 zone_manager::get_manager().load_zones(); // Load character world zones
2892 read_from_file_optional( get_world_base_save_path() + "/uistate.json", []( std::istream & stream ) {
2893 JsonIn jsin( stream );
2894 uistate.deserialize( jsin );
2895 } );
2896 reload_npcs();
2901 update_map( u );
2902 for( auto &e : u.inv_dump() ) {
2903 e->set_owner( g->u );
2904 }
2905 // legacy, needs to be here as we access the map.
2906 if( !u.getID().is_valid() ) {
2907 // player does not have a real id, so assign a new one,
2908 u.setID( assign_npc_id() );
2909 // The vehicle stores the IDs of the boarded players, so update it, too.
2910 if( u.in_vehicle ) {
2912 u.pos() ).part_with_feature( "BOARDABLE", true ) ) {
2913 vp->part().passenger_id = u.getID();
2914 }
2915 }
2916 }
2917
2918 // populate calendar caches now, after active world is set, but before we do
2919 // anything else, to ensure they pick up the correct value from the save's
2920 // worldoptions
2921 calendar::set_eternal_season( ::get_option<bool>( "ETERNAL_SEASON" ) );
2922 calendar::set_season_length( ::get_option<int>( "SEASON_LENGTH" ) );
2923
2924 u.reset();
2925
2926 return true;
2927}
bool read_from_file(const std::string &path, const std::function< void(std::istream &)> &reader)
Try to open and read from given file using the given callback.
bool read_from_file_optional(const std::string &path, const std::function< void(std::istream &)> &reader)
void setID(character_id i, bool force=false)
Definition: character.cpp:454
std::vector< item * > inv_dump()
Definition: character.cpp:8791
void recalc_sight_limits()
Modifies the player's sight values Must be called when any of the following change: This must be call...
Definition: character.cpp:1687
void reset() override
Handles stat and bonus reset.
Definition: character.cpp:3491
Definition: json.h:177
Definition: avatar.h:54
void load_map_memory()
Definition: avatar.cpp:132
bool is_valid() const
Definition: character_id.h:19
void validate_linked_vehicles()
validate towed vehicles so they get linked up again after a load
Definition: game.cpp:1976
void reload_npcs()
Unloads, then loads the NPCs.
Definition: game.cpp:957
void validate_camps()
validate camps to ensure they are on the overmap list
Definition: game.cpp:2034
void load_master()
Definition: game.cpp:2810
void validate_mounted_npcs()
Definition: game.cpp:1991
character_id assign_npc_id()
Definition: game.cpp:3927
void unserialize(std::istream &fin)
Definition: savegame.cpp:169
void init_autosave()
Definition: game.cpp:11784
void validate_npc_followers()
validate list of followers to account for overmap buffers
Definition: game.cpp:2010
void load(std::istream &fin)
Loads the data in a memorial file from the given ifstream.
void load_character()
Create a popup on the UI stack that gets displayed but receives no input itself.
Definition: popup.h:276
void deserialize(const JsonObject &jo)
time_point nextweather
Definition: weather.h:205
void load_zones()
Definition: clzones.cpp:1213
static const std::string SAVE_EXTENSION(".sav")
static const std::string SAVE_EXTENSION_SHORTCUTS(".shortcuts")
static const std::string SAVE_EXTENSION_LOG(".log")
void set_season_length(int dur)
Definition: calendar.cpp:478
void set_eternal_season(bool is_eternal_season)
Definition: calendar.cpp:470

References _, assign_npc_id(), uistatedata::deserialize(), g, gamemode, get_auto_notes_settings(), get_auto_pickup(), zone_manager::get_manager(), get_safemode(), get_weather, get_world_base_save_path(), Character::getID(), Character::in_vehicle, init_autosave(), Character::inv_dump(), character_id::is_valid(), auto_notes::auto_note_settings::load(), memorial_logger::load(), auto_pickup::player_settings::load_character(), safemode::load_character(), avatar::load_map_memory(), load_master(), zone_manager::load_zones(), m, memorial(), mostseen, Character::name, om_direction::name(), weather_manager::nextweather, optional_vpart_position::part_with_feature(), popup(), Character::pos(), read_from_file(), read_from_file_optional(), Character::recalc_sight_limits(), ui_manager::redraw(), refresh_display(), reload_npcs(), Character::reset(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAVE_EXTENSION(), SAVE_EXTENSION_LOG(), SAVE_EXTENSION_SHORTCUTS(), calendar::set_eternal_season(), calendar::set_season_length(), Character::setID(), calendar::start_of_cataclysm, calendar::turn, u, uistate, unserialize(), update_map(), validate_camps(), validate_linked_vehicles(), validate_mounted_npcs(), validate_npc_followers(), map::veh_at(), and Character::weapon.

◆ load() [2/2]

bool game::load ( const std::string &  world)

Attempt to load first valid save (if any) in world.

Definition at line 2817 of file game.cpp.

2818{
2819 world_generator->init();
2820 const WORLDPTR wptr = world_generator->get_world( world );
2821 if( !wptr ) {
2822 return false;
2823 }
2824 if( wptr->world_saves.empty() ) {
2825 debugmsg( "world '%s' contains no saves", world );
2826 return false;
2827 }
2828
2829 try {
2830 world_generator->set_active_world( wptr );
2831 g->setup();
2832 g->load( wptr->world_saves.front() );
2833 } catch( const std::exception &err ) {
2834 debugmsg( "cannot load world '%s': %s", world, err.what() );
2835 return false;
2836 }
2837
2838 return true;
2839}
std::vector< save_t > world_saves
Definition: worldfactory.h:61

References debugmsg, g, world_generator, and WORLD::world_saves.

Referenced by quickload().

◆ load_core_data()

void game::load_core_data ( loading_ui ui)

Loads core dynamic data.

May throw.

Definition at line 435 of file game.cpp.

436{
437 // core data can be loaded only once and must be first
438 // anyway.
440
442}
void unload_data()
Deletes and unloads all the data previously loaded with load_data_from_path.
Definition: init.cpp:522
std::string jsondir()
Definition: path_info.cpp:230

References DynamicDataLoader::get_instance(), PATH_INFO::jsondir(), load_data_from_dir(), and DynamicDataLoader::unload_data().

Referenced by check_mod_data(), dump_stats(), and setup().

◆ load_data_from_dir()

void game::load_data_from_dir ( const std::string &  path,
const std::string &  src,
loading_ui ui 
)
protected

Loads dynamic data from the given directory.

May throw.

Definition at line 444 of file game.cpp.

445{
447}
void load_data_from_path(const std::string &path, const std::string &src, loading_ui &ui)
Load all data from json files located in the path (recursive).
Definition: init.cpp:452

References DynamicDataLoader::get_instance(), and DynamicDataLoader::load_data_from_path().

Referenced by check_mod_data(), load_core_data(), and load_packs().

◆ load_map() [1/2]

void game::load_map ( const tripoint pos_sm)

Load the main map at given location, see map::load, in global, absolute submap coordinates.

Definition at line 631 of file game.cpp.

632{
633 // TODO: fix point types
634 load_map( tripoint_abs_sm( pos_sm ) );
635}
void load_map(const tripoint &pos_sm)
Load the main map at given location, see map::load, in global, absolute submap coordinates.
Definition: game.cpp:631
coords::coord_point< tripoint, coords::origin::abs, coords::sm > tripoint_abs_sm
Definition: coordinates.h:490

References load_map().

Referenced by load_map(), place_player_overmap(), start_game(), and unserialize().

◆ load_map() [2/2]

void game::load_map ( const tripoint_abs_sm pos_sm)

Definition at line 637 of file game.cpp.

638{
639 m.load( pos_sm, true );
640 grid_tracker_ptr->load( m );
641}
void load(const tripoint &w, bool update_vehicles)
Load submaps into grid.
Definition: map.cpp:6508

References grid_tracker_ptr, map::load(), and m.

◆ load_master()

void game::load_master ( )
private

Definition at line 2810 of file game.cpp.

2811{
2812 using namespace std::placeholders;
2813 const auto datafile = get_world_base_save_path() + "/" + SAVE_MASTER;
2814 read_from_file_optional( datafile, std::bind( &game::unserialize_master, this, _1 ) );
2815}
void unserialize_master(std::istream &fin)
Definition: savegame.cpp:1209
static const std::string SAVE_MASTER("master.gsav")

References get_world_base_save_path(), read_from_file_optional(), SAVE_MASTER(), and unserialize_master().

Referenced by load(), and start_game().

◆ load_npcs()

void game::load_npcs ( )

Makes any nearby NPCs on the overmap active.

Definition at line 895 of file game.cpp.

896{
897 const int radius = HALF_MAPSIZE - 1;
898 // uses submap coordinates
899 std::vector<shared_ptr_fast<npc>> just_added;
900 for( const auto &temp : overmap_buffer.get_npcs_near_player( radius ) ) {
901 const character_id &id = temp->getID();
902 const auto found = std::find_if( active_npc.begin(), active_npc.end(),
903 [id]( const shared_ptr_fast<npc> &n ) {
904 return n->getID() == id;
905 } );
906 if( found != active_npc.end() ) {
907 continue;
908 }
909 if( temp->is_active() ) {
910 continue;
911 }
912 if( temp->has_companion_mission() ) {
913 continue;
914 }
915
916 const tripoint sm_loc = temp->global_sm_location();
917 // NPCs who are out of bounds before placement would be pushed into bounds
918 // This can cause NPCs to teleport around, so we don't want that
919 if( sm_loc.x < get_levx() || sm_loc.x >= get_levx() + MAPSIZE ||
920 sm_loc.y < get_levy() || sm_loc.y >= get_levy() + MAPSIZE ||
921 ( sm_loc.z != get_levz() && !m.has_zlevels() ) ) {
922 continue;
923 }
924
925 add_msg( m_debug, "game::load_npcs: Spawning static NPC, %d:%d:%d (%d:%d:%d)",
926 get_levx(), get_levy(), get_levz(), sm_loc.x, sm_loc.y, sm_loc.z );
927 temp->place_on_map();
928 if( !m.inbounds( temp->pos() ) ) {
929 continue;
930 }
931 // In the rare case the npc was marked for death while
932 // it was on the overmap. Kill it.
933 if( temp->marked_for_death ) {
934 temp->die( nullptr );
935 } else {
936 active_npc.push_back( temp );
937 just_added.push_back( temp );
938 }
939 }
940
941 for( const auto &npc : just_added ) {
942 npc->on_load();
943 }
944
945 npcs_dirty = false;
946}
void on_load()
Retroactively update npc.
Definition: npc.cpp:2655
static constexpr int MAPSIZE

References active_npc, add_msg(), get_levx(), get_levy(), get_levz(), overmapbuffer::get_npcs_near_player(), HALF_MAPSIZE, map::has_zlevels(), map::inbounds(), m, m_debug, MAPSIZE, npcs_dirty, npc::on_load(), overmap_buffer, tripoint::x, tripoint::y, and tripoint::z.

Referenced by do_turn(), perhaps_add_random_npc(), place_player_overmap(), reload_npcs(), save_cyborg(), spawn_hallucination(), start_game(), and update_map().

◆ load_packs()

bool game::load_packs ( const std::string &  msg,
const std::vector< mod_id > &  packs,
loading_ui ui 
)

Load content packs.

Parameters
msgstring to display whilst loading prompt
packscontent packs to load in correct dependent order
uistructure for load progress display
Returns
true if all packs were found, false if any were missing

Definition at line 2965 of file game.cpp.

2966{
2967 ui.new_context( msg );
2968 std::vector<mod_id> missing;
2969 std::vector<mod_id> available;
2970
2971 for( const mod_id &e : packs ) {
2972 if( e.is_valid() ) {
2973 available.emplace_back( e );
2974 ui.add_entry( e->name() );
2975 } else {
2976 missing.push_back( e );
2977 }
2978 }
2979
2980 ui.show();
2981 for( const auto &e : available ) {
2982 const MOD_INFORMATION &mod = *e;
2983 load_data_from_dir( mod.path, mod.ident.str(), ui );
2984 ui.proceed();
2985 }
2986
2987 for( const auto &e : missing ) {
2988 debugmsg( "unknown content %s", e.c_str() );
2989 }
2990
2991 return missing.empty();
2992}

References available, string_id< T >::c_str(), debugmsg, string_id< T >::is_valid(), load_data_from_dir(), and MOD_INFORMATION::name().

Referenced by dump_stats().

◆ load_static_data()

void game::load_static_data ( )

Loads static data that does not depend on mods or similar.

Definition at line 321 of file game.cpp.

322{
323 // UI stuff, not mod-specific per definition
324 inp_mngr.init(); // Load input config JSON
325 // Init mappings for loading the json stuff
327 fullscreen = false;
328 was_fullscreen = false;
329 show_panel_adm = false;
331
332 // These functions do not load stuff from json.
333 // The content they load/initialize is hardcoded into the program.
334 // Therefore they can be loaded here.
335 // If this changes (if they load data from json), they have to
336 // be moved to game::load_mod or game::load_core_data
337
340}
bool was_fullscreen
Definition: game.h:1065
bool fullscreen
Definition: game.h:1064
void init()
Initializes the input manager, aka loads the input mapping configuration JSON.
Definition: input.cpp:111
void init()
Definition: panels.cpp:2305
void load_global()

References fullscreen, get_auto_pickup(), DynamicDataLoader::get_instance(), panel_manager::get_manager(), get_safemode(), input_manager::init(), panel_manager::init(), inp_mngr, auto_pickup::player_settings::load_global(), safemode::load_global(), show_panel_adm, and was_fullscreen.

◆ load_world_modfiles()

void game::load_world_modfiles ( loading_ui ui)

Loads core data and mods from the active world.

May throw.

Definition at line 2929 of file game.cpp.

2930{
2931 auto &mods = world_generator->active_world->active_mod_order;
2932
2933 // remove any duplicates whilst preserving order (fixes #19385)
2934 std::set<mod_id> found;
2935 mods.erase( std::remove_if( mods.begin(), mods.end(), [&found]( const mod_id & e ) {
2936 if( found.count( e ) ) {
2937 return true;
2938 } else {
2939 found.insert( e );
2940 return false;
2941 }
2942 } ), mods.end() );
2943
2944 // require at least one core mod (saves before version 6 may implicitly require dda pack)
2945 if( std::none_of( mods.begin(), mods.end(), []( const mod_id & e ) {
2946 return e->core;
2947} ) ) {
2948 mods.insert( mods.begin(), mod_id( "dda" ) );
2949 }
2950
2952 // this code does not care about mod dependencies,
2953 // it assumes that those dependencies are static and
2954 // are resolved during the creation of the world.
2955 // That means world->active_mod_order contains a list
2956 // of mods in the correct order.
2957 load_packs( _( "Loading files" ), mods, ui );
2958
2959 // Load additional mods from that world-specific folder
2960 load_data_from_dir( get_world_base_save_path() + "/mods", "custom", ui );
2961
2963}
void load_artifacts(const std::string &path)
Definition: artifact.cpp:1098
static const std::string SAVE_ARTIFACTS("artifacts.gsav")

References world_generator.

Referenced by setup().

◆ look_around() [1/2]

cata::optional< tripoint > game::look_around ( )

Definition at line 6835 of file game.cpp.

6836{
6838 look_around_result result = look_around( /*show_window=*/true, center, center, false, false,
6839 false );
6840 return result.position;
6841}

References center, look_around(), Character::pos(), u, and player::view_offset.

Referenced by handle_action(), list_monsters(), look_around(), peek(), and zones_manager().

◆ look_around() [2/2]

look_around_result game::look_around ( bool  show_window,
tripoint center,
const tripoint start_point,
bool  has_first_point,
bool  select_zone,
bool  peeking,
bool  is_moving_zone = false,
const tripoint end_point = tripoint_zero 
)
Parameters
show_windowdisplay the info window that holds the tile information in the position.
centerused to calculate the u.view_offset, could center the screen to the position it represents
start_pointthe start point of the targeting zone, also the initial local position of the cursor
has_first_pointshould be true if the first point has been selected when editing the zone
select_zonetrue if the zone is being edited
peekingdetermines if the player is peeking
is_moving_zonetrue if the zone is being moved, false by default
end_pointthe end point of the targeting zone, only used if is_moving_zone is true, default is tripoint_zero
Returns
look_around_result

Definition at line 6843 of file game.cpp.

6846{
6847 bVMonsterLookFire = false;
6848 // TODO: Make this `true`
6849 const bool allow_zlev_move = m.has_zlevels() && get_option<bool>( "FOV_3D" );
6850
6852
6853 tripoint lp = is_moving_zone ? ( start_point + end_point ) / 2 : start_point; // cursor
6854 int &lx = lp.x;
6855 int &ly = lp.y;
6856 int &lz = lp.z;
6857
6858 int soffset = get_option<int>( "FAST_SCROLL_OFFSET" );
6859 bool fast_scroll = false;
6860
6861 std::unique_ptr<ui_adaptor> ui;
6862 catacurses::window w_info;
6863 if( show_window ) {
6864 ui = std::make_unique<ui_adaptor>();
6865 ui->on_screen_resize( [&]( ui_adaptor & ui ) {
6866 int panel_width = panel_manager::get_manager().get_current_layout().begin()->get_width();
6868
6869 // If particularly small, base height on panel width irrespective of other elements.
6870 // Value here is attempting to get a square-ish result assuming 1x2 proportioned font.
6871 if( height < panel_width / 2 ) {
6872 height = panel_width / 2;
6873 }
6874
6875 int la_y = 0;
6876 int la_x = TERMX - panel_width;
6877 std::string position = get_option<std::string>( "LOOKAROUND_POSITION" );
6878 if( position == "left" ) {
6879 if( get_option<std::string>( "SIDEBAR_POSITION" ) == "right" ) {
6881 } else {
6882 la_x = panel_manager::get_manager().get_width_left() - panel_width;
6883 }
6884 }
6885 int la_h = height;
6886 int la_w = panel_width;
6887 w_info = catacurses::newwin( la_h, la_w, point( la_x, la_y ) );
6888
6889 ui.position_from_window( w_info );
6890 } );
6891 ui->mark_resize();
6892 }
6893
6894 std::string action;
6895 input_context ctxt( "LOOK" );
6896 ctxt.set_iso( true );
6897 ctxt.register_directions();
6898 ctxt.register_action( "COORDINATE" );
6899 ctxt.register_action( "LEVEL_UP" );
6900 ctxt.register_action( "LEVEL_DOWN" );
6901 ctxt.register_action( "TOGGLE_FAST_SCROLL" );
6902 ctxt.register_action( "EXTENDED_DESCRIPTION" );
6903 ctxt.register_action( "SELECT" );
6904 if( peeking ) {
6905 ctxt.register_action( "throw_blind" );
6906 }
6907 if( !select_zone ) {
6908 ctxt.register_action( "TRAVEL_TO" );
6909 ctxt.register_action( "LIST_ITEMS" );
6910 }
6911 ctxt.register_action( "MOUSE_MOVE" );
6912 ctxt.register_action( "CENTER" );
6913
6914 ctxt.register_action( "debug_scent" );
6915 ctxt.register_action( "debug_scent_type" );
6916 ctxt.register_action( "debug_temp" );
6917 ctxt.register_action( "debug_visibility" );
6918 ctxt.register_action( "debug_lighting" );
6919 ctxt.register_action( "debug_radiation" );
6920 ctxt.register_action( "debug_submap_grid" );
6921 ctxt.register_action( "debug_hour_timer" );
6922 ctxt.register_action( "CONFIRM" );
6923 ctxt.register_action( "QUIT" );
6924 ctxt.register_action( "HELP_KEYBINDINGS" );
6925 if( use_tiles ) {
6926 ctxt.register_action( "zoom_out" );
6927 ctxt.register_action( "zoom_in" );
6928 }
6929#if defined(TILES)
6930 ctxt.register_action( "toggle_pixel_minimap" );
6931#endif // TILES
6932
6933 const int old_levz = get_levz();
6934 const int min_levz = std::max( old_levz - fov_3d_z_range, -OVERMAP_DEPTH );
6935 const int max_levz = std::min( old_levz + fov_3d_z_range, OVERMAP_HEIGHT );
6936
6937 m.update_visibility_cache( old_levz );
6938 const visibility_variables &cache = g->m.get_visibility_variables_cache();
6939
6940 bool blink = true;
6942
6943 shared_ptr_fast<draw_callback_t> ter_indicator_cb;
6944
6945 if( show_window && ui ) {
6946 ui->on_redraw( [&]( const ui_adaptor & ) {
6947 werase( w_info );
6948 draw_border( w_info );
6949
6950 center_print( w_info, 0, c_white, string_format( _( "< <color_green>Look Around</color> >" ) ) );
6951
6952 std::string extended_descr_text = string_format( _( "%s - %s" ),
6953 ctxt.get_desc( "EXTENDED_DESCRIPTION" ),
6954 ctxt.get_action_name( "EXTENDED_DESCRIPTION" ) );
6955 std::string fast_scroll_text = string_format( _( "%s - %s" ),
6956 ctxt.get_desc( "TOGGLE_FAST_SCROLL" ),
6957 ctxt.get_action_name( "TOGGLE_FAST_SCROLL" ) );
6958#if defined(TILES)
6959 std::string pixel_minimap_text = string_format( _( "%s - %s" ),
6960 ctxt.get_desc( "toggle_pixel_minimap" ),
6961 ctxt.get_action_name( "toggle_pixel_minimap" ) );
6962#endif // TILES
6963
6964 center_print( w_info, getmaxy( w_info ) - 2, c_light_gray, extended_descr_text );
6965 mvwprintz( w_info, point( 1, getmaxy( w_info ) - 1 ), fast_scroll ? c_light_green : c_green,
6966 fast_scroll_text );
6967#if defined(TILES)
6968 right_print( w_info, getmaxy( w_info ) - 1, 1, pixel_minimap_option ? c_light_green : c_green,
6969 pixel_minimap_text );
6970#endif // TILES
6971
6972 int first_line = 1;
6973 const int last_line = getmaxy( w_info ) - 3;
6974 pre_print_all_tile_info( lp, w_info, first_line, last_line, cache );
6975
6976 wnoutrefresh( w_info );
6977 } );
6978 ter_indicator_cb = make_shared_fast<draw_callback_t>( [&]() {
6979 draw_look_around_cursor( lp, cache );
6980 } );
6981 add_draw_callback( ter_indicator_cb );
6982 }
6983
6984 cata::optional<tripoint> zone_start;
6985 cata::optional<tripoint> zone_end;
6986 bool zone_blink = false;
6987 bool zone_cursor = true;
6988 shared_ptr_fast<draw_callback_t> zone_cb = create_zone_callback( zone_start, zone_end, zone_blink,
6989 zone_cursor, is_moving_zone );
6990 add_draw_callback( zone_cb );
6991
6992 is_looking = true;
6993 const tripoint prev_offset = u.view_offset;
6994#if defined(TILES)
6995 const int prev_tileset_zoom = tileset_zoom;
6996 while( is_moving_zone && square_dist( start_point, end_point ) > 256 / get_zoom() &&
6997 get_zoom() != 4 ) {
6998 zoom_out();
6999 }
7001#endif
7002 do {
7003 u.view_offset = center - u.pos();
7004 if( select_zone ) {
7005 if( has_first_point ) {
7006 zone_start = start_point;
7007 zone_end = lp;
7008 } else {
7009 zone_start = lp;
7010 zone_end = cata::nullopt;
7011 }
7012 // Actually accessed from the terrain overlay callback `zone_cb` in the
7013 // call to `ui_manager::redraw`.
7014 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
7015 zone_blink = blink;
7016 }
7017
7018 if( is_moving_zone ) {
7019 zone_start = lp - ( start_point + end_point ) / 2 + start_point;
7020 zone_end = lp - ( start_point + end_point ) / 2 + end_point;
7021 // Actually accessed from the terrain overlay callback `zone_cb` in the
7022 // call to `ui_manager::redraw`.
7023 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
7024 zone_blink = blink;
7025 }
7028 if( ( select_zone && has_first_point ) || is_moving_zone ) {
7029 ctxt.set_timeout( BLINK_SPEED );
7030 }
7031
7032 //Wait for input
7033 // only specify a timeout here if "EDGE_SCROLL" is enabled
7034 // otherwise use the previously set timeout
7035 const tripoint edge_scroll = mouse_edge_scrolling_terrain( ctxt );
7036 const int scroll_timeout = get_option<int>( "EDGE_SCROLL" );
7037 const bool edge_scrolling = edge_scroll != tripoint_zero && scroll_timeout >= 0;
7038 if( edge_scrolling ) {
7039 action = ctxt.handle_input( scroll_timeout );
7040 } else {
7041 action = ctxt.handle_input();
7042 }
7043 if( ( action == "LEVEL_UP" || action == "LEVEL_DOWN" || action == "MOUSE_MOVE" ||
7044 ctxt.get_direction( action ) ) && ( ( select_zone && has_first_point ) || is_moving_zone ) ) {
7045 blink = true; // Always draw blink symbols when moving cursor
7046 } else if( action == "TIMEOUT" ) {
7047 blink = !blink;
7048 }
7049 if( action == "LIST_ITEMS" ) {
7051 } else if( action == "TOGGLE_FAST_SCROLL" ) {
7052 fast_scroll = !fast_scroll;
7053 } else if( action == "toggle_pixel_minimap" ) {
7055
7056 if( show_window && ui ) {
7057 ui->mark_resize();
7058 }
7059 } else if( action == "LEVEL_UP" || action == "LEVEL_DOWN" ) {
7060 if( !allow_zlev_move ) {
7061 continue;
7062 }
7063
7064 const int dz = ( action == "LEVEL_UP" ? 1 : -1 );
7065 lz = clamp( lz + dz, min_levz, max_levz );
7066 center.z = clamp( center.z + dz, min_levz, max_levz );
7067
7068 add_msg( m_debug, "levx: %d, levy: %d, levz: %d", get_levx(), get_levy(), center.z );
7069 u.view_offset.z = center.z - u.posz();
7071 } else if( action == "TRAVEL_TO" ) {
7072 if( !u.sees( lp ) ) {
7073 add_msg( _( "You can't see that destination." ) );
7074 continue;
7075 }
7076
7077 auto route = m.route( u.pos(), lp, u.get_pathfinding_settings(), u.get_path_avoid() );
7078 if( route.size() > 1 ) {
7079 route.pop_back();
7080 u.set_destination( route );
7081 } else {
7082 add_msg( m_info, _( "You can't travel there." ) );
7083 continue;
7084 }
7085 } else if( action == "debug_scent" || action == "debug_scent_type" ) {
7087 display_scent();
7088 }
7089 } else if( action == "debug_temp" ) {
7092 }
7093 } else if( action == "debug_lighting" ) {
7096 }
7097 } else if( action == "debug_transparency" ) {
7100 }
7101 } else if( action == "debug_radiation" ) {
7104 }
7105 } else if( action == "debug_submap_grid" ) {
7106 g->debug_submap_grid_overlay = !g->debug_submap_grid_overlay;
7107 } else if( action == "debug_hour_timer" ) {
7109 } else if( action == "EXTENDED_DESCRIPTION" ) {
7111 } else if( action == "CENTER" ) {
7112 center = u.pos();
7113 lp = u.pos();
7114 u.view_offset.z = 0;
7115 } else if( action == "MOUSE_MOVE" || action == "TIMEOUT" ) {
7116 // This block is structured this way so that edge scroll can work
7117 // whether the mouse is moving at the edge or simply stationary
7118 // at the edge. But even if edge scroll isn't in play, there's
7119 // other things for us to do here.
7120
7121 if( edge_scrolling ) {
7122 center += action == "MOUSE_MOVE" ? edge_scroll * 2 : edge_scroll;
7123 } else if( action == "MOUSE_MOVE" ) {
7124 const cata::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
7125 if( mouse_pos ) {
7126 lx = mouse_pos->x;
7127 ly = mouse_pos->y;
7128 }
7129 }
7130 } else if( cata::optional<tripoint> vec = ctxt.get_direction( action ) ) {
7131 if( fast_scroll ) {
7132 vec->x *= soffset;
7133 vec->y *= soffset;
7134 }
7135
7136 lx = lx + vec->x;
7137 ly = ly + vec->y;
7138 center.x = center.x + vec->x;
7139 center.y = center.y + vec->y;
7140 } else if( action == "throw_blind" ) {
7141 result.peek_action = PA_BLIND_THROW;
7142 } else if( action == "zoom_in" ) {
7143 center.x = lp.x;
7144 center.y = lp.y;
7145 zoom_in();
7147 } else if( action == "zoom_out" ) {
7148 center.x = lp.x;
7149 center.y = lp.y;
7150 zoom_out();
7152 }
7153 } while( action != "QUIT" && action != "CONFIRM" && action != "SELECT" && action != "TRAVEL_TO" &&
7154 action != "throw_blind" );
7155
7156 if( m.has_zlevels() && center.z != old_levz ) {
7157 m.invalidate_map_cache( old_levz );
7158 m.build_map_cache( old_levz );
7159 u.view_offset.z = 0;
7160 }
7161
7162 ctxt.reset_timeout();
7163 u.view_offset = prev_offset;
7164 zone_cb = nullptr;
7165 is_looking = false;
7166
7168 bVMonsterLookFire = true;
7169
7170 if( action == "CONFIRM" || action == "SELECT" ) {
7171 result.position = is_moving_zone ? zone_start : lp;
7172 }
7173
7174#if defined(TILES)
7175 if( is_moving_zone && get_zoom() != prev_tileset_zoom ) {
7176 // Reset the tileset zoom to the previous value
7177 set_zoom( prev_tileset_zoom );
7179 }
7180#endif
7181
7182 return result;
7183}
int fov_3d_z_range
3D FoV range, in Z levels, in both directions.
bool pixel_minimap_option
Whether to show the pixel minimap.
tripoint mouse_edge_scrolling_terrain(input_context &ctxt)
Used to implement mouse "edge scrolling".
Definition: game.cpp:2392
void set_zoom(int level)
Definition: game.cpp:7334
void draw_look_around_cursor(const tripoint &lp, const visibility_variables &cache)
Definition: game.cpp:5948
void extended_description(const tripoint &p)
Long description of (visible) things at tile.
void pre_print_all_tile_info(const tripoint &lp, const catacurses::window &w_info, int &line, int last_line, const visibility_variables &cache)
Definition: game.cpp:6822
int get_zoom() const
Definition: game.cpp:7346
void invalidate_map_cache(const int zlev)
Definition: map.h:458
std::vector< window_panel > & get_current_layout()
Definition: panels.cpp:2273
int square_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:505
static shared_ptr_fast< game::draw_callback_t > create_zone_callback(const cata::optional< tripoint > &zone_start, const cata::optional< tripoint > &zone_end, const bool &zone_blink, const bool &zone_cursor, const bool &is_moving_zone=false)
Definition: game.cpp:3386
@ PA_BLIND_THROW
Definition: game.h:122
static constexpr int OVERMAP_HEIGHT
static constexpr int BLINK_SPEED
static constexpr int OVERMAP_DEPTH
int right_print(const catacurses::window &w, const int line, const int right_indent, const nc_color &FG, const std::string &text)
Definition: output.cpp:461

References _, action, add_draw_callback(), add_msg(), BLINK_SPEED, map::build_map_cache(), bVMonsterLookFire, c_green, c_light_gray, c_light_green, c_white, center, center_print(), clamp(), create_zone_callback(), display_lighting(), display_radiation(), display_scent(), display_temperature(), display_transparency(), draw_border(), draw_look_around_cursor(), extended_description(), fov_3d_z_range, g, input_context::get_action_name(), input_context::get_coordinates(), panel_manager::get_current_layout(), input_context::get_desc(), input_context::get_direction(), get_levx(), get_levy(), get_levz(), panel_manager::get_manager(), Character::get_path_avoid(), Character::get_pathfinding_settings(), panel_manager::get_width_left(), get_zoom(), catacurses::getmaxy(), input_context::handle_input(), map::has_zlevels(), invalidate_main_ui_adaptor(), map::invalidate_map_cache(), is_looking, MAP_SHARING::isCompetitive(), MAP_SHARING::isDebugger(), list_items_monsters(), m, m_debug, m_info, mark_main_ui_adaptor_resize(), mouse_edge_scrolling_terrain(), mvwprintz(), catacurses::newwin(), cata::nullopt, OVERMAP_DEPTH, OVERMAP_HEIGHT, PA_BLIND_THROW, pixel_minimap_option, Character::pos(), Character::posz(), pre_print_all_tile_info(), ui_manager::redraw(), reenter_fullscreen(), input_context::register_action(), input_context::register_directions(), input_context::reset_timeout(), right_print(), map::route(), Character::sees(), Character::set_destination(), input_context::set_iso(), input_context::set_timeout(), set_zoom(), square_dist(), string_format(), temp_exit_fullscreen(), TERMX, TERMY, tileset_zoom, toggle_debug_hour_timer(), toggle_pixel_minimap(), tripoint_zero, u, map::update_visibility_cache(), use_tiles, player::view_offset, w_pixel_minimap, w_terrain, catacurses::werase(), catacurses::wnoutrefresh(), tripoint::x, tripoint::y, tripoint::z, zoom_in(), and zoom_out().

◆ look_debug()

cata::optional< tripoint > game::look_debug ( )

Definition at line 5941 of file game.cpp.

5942{
5943 editmap edit;
5944 return edit.edit();
5945}
cata::optional< tripoint > edit()
Definition: editmap.cpp:338

References editmap::edit().

◆ mark_main_ui_adaptor_resize()

void game::mark_main_ui_adaptor_resize ( ) const

Definition at line 3343 of file game.cpp.

3344{
3346 if( ui ) {
3347 ui->mark_resize();
3348 }
3349}

References main_ui_adaptor.

Referenced by handle_action(), look_around(), toggle_fullscreen(), and toggle_pixel_minimap().

◆ memorial()

memorial_logger & game::memorial ( )

Definition at line 3085 of file game.cpp.

3086{
3087 return *memorial_logger_ptr;
3088}

References memorial_logger_ptr.

Referenced by cleanup_at_end(), load(), save_player_data(), win(), win_screen(), and write_memorial_file().

◆ mon_info()

void game::mon_info ( const catacurses::window w,
int  hor_padding = 0 
)

Definition at line 4034 of file game.cpp.

4035{
4036 const monster_visible_info &mon_visible = u.get_mon_visible();
4037 const auto &unique_types = mon_visible.unique_types;
4038 const auto &unique_mons = mon_visible.unique_mons;
4039 const auto &dangerous = mon_visible.dangerous;
4040
4041 const int width = getmaxx( w ) - 2 * hor_padding;
4042 const int maxheight = getmaxy( w );
4043
4044 const int startrow = 0;
4045
4046 // Print the direction headings
4047 // Reminder:
4048 // 7 0 1 unique_types uses these indices;
4049 // 6 8 2 0-7 are provide by direction_from()
4050 // 5 4 3 8 is used for local monsters (for when we explain them below)
4051
4052 const std::array<std::string, 8> dir_labels = {{
4053 _( "North:" ), _( "NE:" ), _( "East:" ), _( "SE:" ),
4054 _( "South:" ), _( "SW:" ), _( "West:" ), _( "NW:" )
4055 }
4056 };
4057 std::array<int, 8> widths;
4058 for( int i = 0; i < 8; i++ ) {
4059 widths[i] = utf8_width( dir_labels[i] );
4060 }
4061 std::array<int, 8> xcoords;
4062 const std::array<int, 8> ycoords = {{ 0, 0, 1, 2, 2, 2, 1, 0 }};
4063 xcoords[0] = xcoords[4] = width / 3;
4064 xcoords[1] = xcoords[3] = xcoords[2] = ( width / 3 ) * 2;
4065 xcoords[5] = xcoords[6] = xcoords[7] = 0;
4066 //for the alignment of the 1,2,3 rows on the right edge
4067 xcoords[2] -= utf8_width( _( "East:" ) ) - utf8_width( _( "NE:" ) );
4068 for( int i = 0; i < 8; i++ ) {
4069 nc_color c = unique_types[i].empty() && unique_mons[i].empty() ? c_dark_gray
4070 : ( dangerous[i] ? c_light_red : c_light_gray );
4071 mvwprintz( w, point( xcoords[i] + hor_padding, ycoords[i] + startrow ), c, dir_labels[i] );
4072 }
4073
4074 // Print the symbols of all monsters in all directions.
4075 for( int i = 0; i < 8; i++ ) {
4076 point pr( xcoords[i] + widths[i] + 1, ycoords[i] + startrow );
4077
4078 // The list of symbols needs a space on each end.
4079 int symroom = ( width / 3 ) - widths[i] - 2;
4080 const int typeshere_npc = unique_types[i].size();
4081 const int typeshere_mon = unique_mons[i].size();
4082 const int typeshere = typeshere_mon + typeshere_npc;
4083 for( int j = 0; j < typeshere && j < symroom; j++ ) {
4084 nc_color c;
4085 std::string sym;
4086 if( symroom < typeshere && j == symroom - 1 ) {
4087 // We've run out of room!
4088 c = c_white;
4089 sym = "+";
4090 } else if( j < typeshere_npc ) {
4091 switch( unique_types[i][j]->get_attitude() ) {
4092 case NPCATT_KILL:
4093 c = c_red;
4094 break;
4095 case NPCATT_FOLLOW:
4096 c = c_light_green;
4097 break;
4098 default:
4099 c = c_pink;
4100 break;
4101 }
4102 sym = "@";
4103 } else {
4104 const mtype &mt = *unique_mons[i][j - typeshere_npc];
4105 c = mt.color;
4106 sym = mt.sym;
4107 }
4108 mvwprintz( w, pr, c, sym );
4109
4110 pr.x++;
4111 }
4112 }
4113
4114 // Now we print their full names!
4115
4116 std::set<const mtype *> listed_mons;
4117
4118 // Start printing monster names on row 4. Rows 0-2 are for labels, and row 3
4119 // is blank.
4120 point pr( hor_padding, 4 + startrow );
4121
4122 // Print monster names, starting with those at location 8 (nearby).
4123 for( int j = 8; j >= 0 && pr.y < maxheight; j-- ) {
4124 // Separate names by some number of spaces (more for local monsters).
4125 int namesep = ( j == 8 ? 2 : 1 );
4126 for( const mtype *type : unique_mons[j] ) {
4127 if( pr.y >= maxheight ) {
4128 // no space to print to anyway
4129 break;
4130 }
4131 if( listed_mons.count( type ) > 0 ) {
4132 // this type is already printed.
4133 continue;
4134 }
4135 listed_mons.insert( type );
4136
4137 const mtype &mt = *type;
4138 const std::string name = mt.nname();
4139
4140 // Move to the next row if necessary. (The +2 is for the "Z ").
4141 if( pr.x + 2 + utf8_width( name ) >= width ) {
4142 pr.y++;
4143 pr.x = hor_padding;
4144 }
4145
4146 if( pr.y < maxheight ) { // Don't print if we've overflowed
4147 mvwprintz( w, pr, mt.color, mt.sym );
4148 pr.x += 2; // symbol and space
4149 nc_color danger = c_dark_gray;
4150 if( mt.difficulty >= 30 ) {
4151 danger = c_red;
4152 } else if( mt.difficulty >= 16 ) {
4153 danger = c_light_red;
4154 } else if( mt.difficulty >= 8 ) {
4155 danger = c_white;
4156 } else if( mt.agro > 0 ) {
4157 danger = c_light_gray;
4158 }
4159 mvwprintz( w, pr, danger, name );
4160 pr.x += utf8_width( name ) + namesep;
4161 }
4162 }
4163 }
4164}
@ NPCATT_KILL
Definition: npc.h:91
@ NPCATT_FOLLOW
Definition: npc.h:84
std::vector< const mtype * > unique_mons[9]
Definition: avatar.h:47
bool dangerous[8]
Definition: avatar.h:50
std::vector< npc * > unique_types[9]
Definition: avatar.h:46
Definition: mtype.h:208
std::string sym
UTF-8 encoded symbol, should be exactly one cell wide.
Definition: mtype.h:253
nc_color color
Definition: mtype.h:258
int difficulty
Definition: mtype.h:264
int agro
e.g.
Definition: mtype.h:269

References _, mtype::agro, c, c_dark_gray, c_light_gray, c_light_green, c_light_red, c_pink, c_red, c_white, mtype::color, monster_visible_info::dangerous, mtype::difficulty, avatar::get_mon_visible(), catacurses::getmaxx(), catacurses::getmaxy(), mvwprintz(), om_direction::name(), mtype::nname(), NPCATT_FOLLOW, NPCATT_KILL, mtype::sym, type, u, monster_visible_info::unique_mons, monster_visible_info::unique_types, utf8_width(), point::x, and point::y.

◆ mon_info_update()

void game::mon_info_update ( )

Definition at line 4166 of file game.cpp.

4167{
4168 int newseen = 0;
4169 const int safe_proxy_dist = get_option<int>( "SAFEMODEPROXIMITY" );
4170 const int iProxyDist = ( safe_proxy_dist <= 0 ) ? MAX_VIEW_DISTANCE :
4171 safe_proxy_dist;
4172
4173 monster_visible_info &mon_visible = u.get_mon_visible();
4174 auto &new_seen_mon = mon_visible.new_seen_mon;
4175 auto &unique_types = mon_visible.unique_types;
4176 auto &unique_mons = mon_visible.unique_mons;
4177 auto &dangerous = mon_visible.dangerous;
4178
4179 // 7 0 1 unique_types uses these indices;
4180 // 6 8 2 0-7 are provide by direction_from()
4181 // 5 4 3 8 is used for local monsters (for when we explain them below)
4182 for( auto &t : unique_types ) {
4183 t.clear();
4184 }
4185 for( auto &m : unique_mons ) {
4186 m.clear();
4187 }
4188 std::fill( dangerous, dangerous + 8, false );
4189
4190 const tripoint view = u.pos() + u.view_offset;
4191 new_seen_mon.clear();
4192
4193 // TODO: no reason to have it static here
4194 static time_point previous_turn = calendar::start_of_cataclysm;
4195 const time_duration sm_ignored_time = time_duration::from_turns(
4196 get_option<int>( "SAFEMODEIGNORETURNS" ) );
4197
4199 monster *m = dynamic_cast<monster *>( c );
4200 npc *p = dynamic_cast<npc *>( c );
4201 const direction dir_to_mon = direction_from( view.xy(), point( c->posx(), c->posy() ) );
4202 const int mx = POSX + ( c->posx() - view.x );
4203 const int my = POSY + ( c->posy() - view.y );
4204 int index = 8;
4205 if( !is_valid_in_w_terrain( point( mx, my ) ) ) {
4206 // for compatibility with old code, see diagram below, it explains the values for index,
4207 // also might need revisiting one z-levels are in.
4208 switch( dir_to_mon ) {
4212 index = 7;
4213 break;
4215 case direction::NORTH:
4217 index = 0;
4218 break;
4222 index = 1;
4223 break;
4225 case direction::WEST:
4227 index = 6;
4228 break;
4230 case direction::CENTER:
4232 index = 8;
4233 break;
4235 case direction::EAST:
4237 index = 2;
4238 break;
4242 index = 5;
4243 break;
4245 case direction::SOUTH:
4247 index = 4;
4248 break;
4252 index = 3;
4253 break;
4254 }
4255 }
4256
4257 rule_state safemode_state = RULE_NONE;
4258 const bool safemode_empty = get_safemode().empty();
4259
4260 if( m != nullptr ) {
4261 //Safemode monster check
4262 monster &critter = *m;
4263
4264 const monster_attitude matt = critter.attitude( &u );
4265 const int mon_dist = rl_dist( u.pos(), critter.pos() );
4266 safemode_state = get_safemode().check_monster( critter.name(), critter.attitude_to( u ), mon_dist );
4267
4268 if( ( !safemode_empty && safemode_state == RULE_BLACKLISTED ) || ( safemode_empty &&
4269 ( MATT_ATTACK == matt || MATT_FOLLOW == matt ) ) ) {
4270 if( index < 8 && critter.sees( g->u ) ) {
4271 dangerous[index] = true;
4272 }
4273
4274 if( !safemode_empty || mon_dist <= iProxyDist ) {
4275 bool passmon = false;
4276 if( critter.ignoring > 0 ) {
4277 if( safe_mode != SAFE_MODE_ON ) {
4278 critter.ignoring = 0;
4279 } else if( ( sm_ignored_time == 0_seconds || ( critter.lastseen_turn &&
4280 *critter.lastseen_turn > calendar::turn - sm_ignored_time ) ) &&
4281 ( mon_dist > critter.ignoring / 2 || mon_dist < 6 ) ) {
4282 passmon = true;
4283 }
4284 critter.lastseen_turn = calendar::turn;
4285 }
4286
4287 if( !passmon ) {
4288 newseen++;
4289 new_seen_mon.push_back( shared_from( critter ) );
4290 }
4291 }
4292 }
4293
4294 std::vector<const mtype *> &vec = unique_mons[index];
4295 if( std::find( vec.begin(), vec.end(), critter.type ) == vec.end() ) {
4296 vec.push_back( critter.type );
4297 }
4298 } else if( p != nullptr ) {
4299 //Safe mode NPC check
4300
4301 const int npc_dist = rl_dist( u.pos(), p->pos() );
4302 safemode_state = get_safemode().check_monster( get_safemode().npc_type_name(), p->attitude_to( u ),
4303 npc_dist );
4304
4305 if( ( !safemode_empty && safemode_state == RULE_BLACKLISTED ) || ( safemode_empty &&
4306 p->get_attitude() == NPCATT_KILL ) ) {
4307 if( !safemode_empty || npc_dist <= iProxyDist ) {
4308 newseen++;
4309 }
4310 }
4311 unique_types[index].push_back( p );
4312 }
4313 }
4314
4315 if( newseen > mostseen ) {
4316 if( newseen - mostseen == 1 ) {
4317 if( !new_seen_mon.empty() ) {
4318 monster &critter = *new_seen_mon.back();
4320 string_format( _( "%s spotted!" ), critter.name() ) );
4321 if( u.has_trait( trait_id( "M_DEFENDER" ) ) && critter.type->in_species( PLANT ) ) {
4322 add_msg( m_warning, _( "We have detected a %s - an enemy of the Mycus!" ), critter.name() );
4324 u.add_effect( effect_adrenaline_mycus, 30_minutes );
4325 } else if( u.get_effect_int( effect_adrenaline_mycus ) == 1 ) {
4326 // Triffids present. We ain't got TIME to adrenaline comedown!
4327 u.add_effect( effect_adrenaline_mycus, 15_minutes );
4328 u.mod_pain( 3 ); // Does take it out of you, though
4329 add_msg( m_info, _( "Our fibers strain with renewed wrath!" ) );
4330 }
4331 }
4332 } else {
4333 //Hostile NPC
4335 _( "Hostile survivor spotted!" ) );
4336 }
4337 } else {
4339 }
4341 if( safe_mode == SAFE_MODE_ON ) {
4343 }
4344 } else if( calendar::turn > previous_turn && get_option<bool>( "AUTOSAFEMODE" ) &&
4345 newseen == 0 ) { // Auto-safe mode, but only if it's a new turn
4346 turnssincelastmon += to_turns<int>( calendar::turn - previous_turn );
4347 if( turnssincelastmon >= get_option<int>( "AUTOSAFEMODETURNS" ) && safe_mode == SAFE_MODE_OFF ) {
4349 add_msg( m_info, _( "Safe mode ON!" ) );
4350 }
4351 }
4352
4353 if( newseen == 0 && safe_mode == SAFE_MODE_STOP ) {
4355 }
4356
4357 previous_turn = calendar::turn;
4358 mostseen = newseen;
4359}
int get_effect_int(const efftype_id &eff_id, body_part bp=num_bp) const
Returns the intensity of the matching effect.
Definition: creature.cpp:1244
virtual bool sees(const Creature &critter) const
The functions check whether this creature can see the target.
Definition: creature.cpp:202
bool cancel_activity_or_ignore_query(distraction_type type, const std::string &text)
Asks if the player wants to cancel their activity and if so cancels it.
Definition: game.cpp:1789
monster_attitude attitude(const Character *u=nullptr) const
Definition: monster.cpp:1066
cata::optional< time_point > lastseen_turn
Definition: monster.h:506
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
Definition: npc.cpp:2074
rule_state check_monster(const std::string &creature_name_in, Creature::Attitude attitude_in, int proximity_in) const
bool empty() const
rule_state
Definition: enums.h:51
@ RULE_NONE
Definition: enums.h:52
bool is_valid_in_w_terrain(const point &p)
Definition: game.cpp:271
static const species_id PLANT("PLANT")
static const efftype_id effect_adrenaline_mycus("adrenaline_mycus")
static constexpr int MAPSIZE_X
monster_attitude
Definition: monster.h:54
@ MATT_FOLLOW
Definition: monster.h:60
@ MATT_ATTACK
Definition: monster.h:61
FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t< Char > &fill)
bool in_species(const species_id &spec) const
Definition: mtype.cpp:122

References _, ABOVECENTER, ABOVEEAST, ABOVENORTH, ABOVENORTHEAST, ABOVENORTHWEST, ABOVESOUTH, ABOVESOUTHEAST, ABOVESOUTHWEST, ABOVEWEST, Creature::add_effect(), add_msg(), monster::attitude(), monster::attitude_to(), npc::attitude_to(), BELOWCENTER, BELOWEAST, BELOWNORTH, BELOWNORTHEAST, BELOWNORTHWEST, BELOWSOUTH, BELOWSOUTHEAST, BELOWSOUTHWEST, BELOWWEST, c, cancel_activity_or_ignore_query(), CENTER, safemode::check_monster(), monster_visible_info::dangerous, direction_from(), EAST, effect_adrenaline_mycus, safemode::empty(), detail::fill(), detail::find(), time_duration::from_turns(), g, npc::get_attitude(), Creature::get_effect_int(), avatar::get_mon_visible(), get_safemode(), Character::get_visible_creatures(), Creature::has_effect(), Character::has_trait(), hostile_spotted_far, monster::ignoring, mtype::in_species(), is_valid_in_w_terrain(), monster::lastseen_turn, m, m_info, m_warning, MAPSIZE_X, MATT_ATTACK, MATT_FOLLOW, MAX_VIEW_DISTANCE, player::mod_pain(), mostseen, monster::name(), monster_visible_info::new_seen_mon, NORTH, NORTHEAST, NORTHWEST, NPCATT_KILL, PLANT, Character::pos(), monster::pos(), POSX, POSY, rl_dist(), RULE_BLACKLISTED, RULE_NONE, safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAFE_MODE_STOP, Creature::sees(), set_safe_mode(), shared_from(), SOUTH, SOUTHEAST, SOUTHWEST, calendar::start_of_cataclysm, string_format(), calendar::turn, turnssincelastmon, monster::type, u, monster_visible_info::unique_mons, monster_visible_info::unique_types, player::view_offset, WEST, tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by do_turn().

◆ monmove()

void game::monmove ( )
private

Definition at line 4396 of file game.cpp.

4397{
4398 cleanup_dead();
4399
4400 for( monster &critter : all_monsters() ) {
4401 // Critters in impassable tiles get pushed away, unless it's not impassable for them
4402 if( !critter.is_dead() && m.impassable( critter.pos() ) && !critter.can_move_to( critter.pos() ) ) {
4403 std::string msg = string_format( "%s can't move to its location! %s %s", critter.name(),
4404 critter.pos().to_string(), m.tername( critter.pos() ) );
4405 dbg( DL::Error ) << msg;
4406 add_msg( m_debug, msg );
4407 bool okay = false;
4408 for( const tripoint &dest : m.points_in_radius( critter.pos(), 3 ) ) {
4409 if( critter.can_move_to( dest ) && is_empty( dest ) ) {
4410 critter.setpos( dest );
4411 okay = true;
4412 break;
4413 }
4414 }
4415 if( !okay ) {
4416 // die of "natural" cause (overpopulation is natural)
4417 critter.die( nullptr );
4418 }
4419 }
4420
4421 if( !critter.is_dead() ) {
4422 critter.process_items();
4423 }
4424
4425 if( !critter.is_dead() ) {
4426 critter.process_turn();
4427 }
4428
4429 m.creature_in_field( critter );
4430 if( calendar::once_every( 1_days ) ) {
4431 if( critter.has_flag( MF_MILKABLE ) ) {
4432 critter.refill_udders();
4433 }
4434 critter.try_reproduce();
4435 }
4436 while( critter.moves > 0 && !critter.is_dead() && !critter.has_effect( effect_ridden ) ) {
4437 critter.made_footstep = false;
4438 // Controlled critters don't make their own plans
4439 if( !critter.has_effect( effect_ai_controlled ) ) {
4440 // Formulate a path to follow
4441 critter.plan();
4442 }
4443 critter.move(); // Move one square, possibly hit u
4444 critter.process_triggers();
4445 m.creature_in_field( critter );
4446 }
4447
4448 if( !critter.is_dead() &&
4449 u.has_active_bionic( bionic_id( "bio_alarm" ) ) &&
4450 u.get_power_level() >= 25_kJ &&
4451 rl_dist( u.pos(), critter.pos() ) <= 5 &&
4452 !critter.is_hallucination() ) {
4453 u.mod_power_level( -25_kJ );
4454 add_msg( m_warning, _( "Your motion alarm goes off!" ) );
4456 _( "Your motion alarm goes off!" ) );
4457 if( u.has_effect( efftype_id( "sleep" ) ) ) {
4458 u.wake_up();
4459 }
4460 }
4461 }
4462
4463 cleanup_dead();
4464
4465 // The remaining monsters are all alive, but may be outside of the reality bubble.
4466 // If so, despawn them. This is not the same as dying, they will be stored for later and the
4467 // monster::die function is not called.
4468 for( monster &critter : all_monsters() ) {
4469 if( critter.posx() < 0 - ( MAPSIZE_X ) / 6 ||
4470 critter.posy() < 0 - ( MAPSIZE_Y ) / 6 ||
4471 critter.posx() > ( MAPSIZE_X * 7 ) / 6 ||
4472 critter.posy() > ( MAPSIZE_Y * 7 ) / 6 ) {
4473 despawn_monster( critter );
4474 }
4475 }
4476
4477 // Now, do active NPCs.
4478 for( npc &guy : g->all_npcs() ) {
4479 int turns = 0;
4480 if( guy.is_mounted() ) {
4481 guy.check_mount_is_spooked();
4482 }
4483 m.creature_in_field( guy );
4484 if( !guy.has_effect( effect_npc_suspend ) ) {
4485 guy.process_turn();
4486 }
4487 while( !guy.is_dead() && guy.moves > 0 && turns < 10 &&
4488 ( !guy.in_sleep_state() || guy.activity.id() == ACT_OPERATION )
4489 ) {
4490 int moves = guy.moves;
4491 guy.move();
4492 if( moves == guy.moves ) {
4493 // Count every time we exit npc::move() without spending any moves.
4494 turns++;
4495 }
4496
4497 // Turn on debug mode when in infinite loop
4498 // It has to be done before the last turn, otherwise
4499 // there will be no meaningful debug output.
4500 if( turns == 9 ) {
4501 debugmsg( "NPC %s entered infinite loop. Turning on debug mode",
4502 guy.name );
4503 debug_mode = true;
4504 }
4505 }
4506
4507 // If we spun too long trying to decide what to do (without spending moves),
4508 // Invoke cognitive suspension to prevent an infinite loop.
4509 if( turns == 10 ) {
4510 add_msg( _( "%s faints!" ), guy.name );
4511 guy.reboot();
4512 }
4513
4514 if( !guy.is_dead() ) {
4515 guy.npc_update_body();
4516 }
4517 }
4518 cleanup_dead();
4519}
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1971
units::energy get_power_level() const
Definition: character.cpp:1951
void wake_up()
Definition: avatar.cpp:947
static const activity_id ACT_OPERATION("ACT_OPERATION")
static const efftype_id effect_npc_suspend("npc_suspend")
static const efftype_id effect_ai_controlled("ai_controlled")
static constexpr int MAPSIZE_Y
@ MF_MILKABLE
Definition: mtype.h:167

References _, ACT_OPERATION, add_msg(), all_monsters(), cancel_activity_or_ignore_query(), cleanup_dead(), map::creature_in_field(), dbg, debug_mode, debugmsg, despawn_monster(), effect_ai_controlled, effect_npc_suspend, effect_ridden, Error, g, Character::get_power_level(), Character::has_active_bionic(), Creature::has_effect(), map::impassable(), is_empty(), m, m_debug, m_warning, MAPSIZE_X, MAPSIZE_Y, MF_MILKABLE, Character::mod_power_level(), motion_alarm, calendar::once_every(), map::points_in_radius(), Character::pos(), rl_dist(), string_format(), map::tername(), u, and avatar::wake_up().

Referenced by do_turn().

◆ mouse_edge_scrolling()

std::pair< tripoint, tripoint > game::mouse_edge_scrolling ( input_context ctxt,
int  speed,
const tripoint last,
bool  iso 
)
private

Definition at line 2339 of file game.cpp.

2341{
2342 const int rate = get_option<int>( "EDGE_SCROLL" );
2343 auto ret = std::make_pair( tripoint_zero, last );
2344 if( rate == -1 ) {
2345 // Fast return when the option is disabled.
2346 return ret;
2347 }
2348 // Ensure the parameters are used even if the #if below is false
2349 ( void ) ctxt;
2350 ( void ) speed;
2351 ( void ) iso;
2352#if (defined TILES || defined _WIN32 || defined WINDOWS)
2353 auto now = std::chrono::steady_clock::now();
2354 if( now < last_mouse_edge_scroll + std::chrono::milliseconds( rate ) ) {
2355 return ret;
2356 } else {
2358 }
2359 const input_event event = ctxt.get_raw_input();
2360 if( event.type == CATA_INPUT_MOUSE ) {
2361 const point threshold( projected_window_width() / 100, projected_window_height() / 100 );
2362 if( event.mouse_pos.x <= threshold.x ) {
2363 ret.first.x -= speed;
2364 if( iso ) {
2365 ret.first.y -= speed;
2366 }
2367 } else if( event.mouse_pos.x >= projected_window_width() - threshold.x ) {
2368 ret.first.x += speed;
2369 if( iso ) {
2370 ret.first.y += speed;
2371 }
2372 }
2373 if( event.mouse_pos.y <= threshold.y ) {
2374 ret.first.y -= speed;
2375 if( iso ) {
2376 ret.first.x += speed;
2377 }
2378 } else if( event.mouse_pos.y >= projected_window_height() - threshold.y ) {
2379 ret.first.y += speed;
2380 if( iso ) {
2381 ret.first.x -= speed;
2382 }
2383 }
2384 ret.second = ret.first;
2385 } else if( event.type == CATA_INPUT_TIMEOUT ) {
2386 ret.first = ret.second;
2387 }
2388#endif
2389 return ret;
2390}
@ CATA_INPUT_TIMEOUT
Definition: input.h:81
@ CATA_INPUT_MOUSE
Definition: input.h:84

References CATA_INPUT_MOUSE, CATA_INPUT_TIMEOUT, input_context::get_raw_input(), iso, last, last_mouse_edge_scroll, cata::hash64_detail::ret, tripoint_zero, point::x, and point::y.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ mouse_edge_scrolling_overmap()

tripoint game::mouse_edge_scrolling_overmap ( input_context ctxt)

This variant is suitable for the overmap.

Definition at line 2401 of file game.cpp.

2402{
2403 // overmap has no iso mode
2407 return ret.first;
2408}
std::pair< tripoint, tripoint > mouse_edge_scrolling(input_context &ctxt, int speed, const tripoint &last, bool iso)
Definition: game.cpp:2339
tripoint last_mouse_edge_scroll_vector_terrain
Definition: game.h:1117
tripoint last_mouse_edge_scroll_vector_overmap
Definition: game.h:1118

References last_mouse_edge_scroll_vector_overmap, last_mouse_edge_scroll_vector_terrain, mouse_edge_scrolling(), cata::hash64_detail::ret, and tripoint_zero.

◆ mouse_edge_scrolling_terrain()

tripoint game::mouse_edge_scrolling_terrain ( input_context ctxt)

Used to implement mouse "edge scrolling".

Returns a tripoint which is a vector of the resulting "move", i.e. (0, 0, 0) if the mouse is not at the edge of the screen, otherwise some (x, y, 0) depending on which edges are hit. This variant adjust scrolling speed according to zoom level, making it suitable when viewing the "terrain".

Definition at line 2392 of file game.cpp.

References DEFAULT_TILESET_ZOOM, last_mouse_edge_scroll_vector_overmap, last_mouse_edge_scroll_vector_terrain, mouse_edge_scrolling(), cata::hash64_detail::ret, tile_iso, tileset_zoom, and tripoint_zero.

Referenced by look_around().

◆ move_save_to_graveyard()

void game::move_save_to_graveyard ( const std::string &  dirname)
private

Definition at line 2772 of file game.cpp.

2773{
2774 const std::string save_dir = get_world_base_save_path();
2775 const std::string graveyard_dir = PATH_INFO::graveyarddir() + "/";
2776 const std::string graveyard_save_dir = graveyard_dir + dirname + "/";
2777 const std::string prefix = base64_encode( u.name ) + ".";
2778
2779 if( !assure_dir_exist( graveyard_dir ) ) {
2780 debugmsg( "could not create graveyard path '%s'", graveyard_dir );
2781 }
2782
2783 if( !assure_dir_exist( graveyard_save_dir ) ) {
2784 debugmsg( "could not create graveyard path '%s'", graveyard_save_dir );
2785 }
2786
2787 const auto save_files = get_files_from_path( prefix, save_dir );
2788 if( save_files.empty() ) {
2789 debugmsg( "could not find save files in '%s'", save_dir );
2790 }
2791
2792 for( const auto &src_path : save_files ) {
2793 const std::string dst_path = graveyard_save_dir +
2794 src_path.substr( src_path.rfind( '/' ), std::string::npos );
2795
2796 if( rename_file( src_path, dst_path ) ) {
2797 continue;
2798 }
2799
2800 debugmsg( "could not rename file '%s' to '%s'", src_path, dst_path );
2801
2802 if( remove_file( src_path ) ) {
2803 continue;
2804 }
2805
2806 debugmsg( "could not remove file '%s'", src_path );
2807 }
2808}
@ prefix
Definition: enums.h:79
bool remove_file(const std::string &path)
Remove a file.
Definition: filesystem.cpp:89
bool assure_dir_exist(const std::string &path)
Create directory if it does not exist.
Definition: filesystem.cpp:48
bool rename_file(const std::string &old_path, const std::string &new_path)
Rename a file, overwriting the target.
Definition: filesystem.cpp:105
std::vector< std::string > get_files_from_path(const std::string &pattern, const std::string &root_path, const bool recursive_search, const bool match_extension)
Returns a vector of files or directories matching pattern at root_path.
Definition: filesystem.cpp:362
std::string graveyarddir()
Definition: path_info.cpp:202

References assure_dir_exist(), base64_encode(), debugmsg, get_files_from_path(), get_world_base_save_path(), PATH_INFO::graveyarddir(), Character::name, prefix, remove_file(), rename_file(), and u.

Referenced by cleanup_at_end().

◆ moving_vehicle_dismount()

void game::moving_vehicle_dismount ( const tripoint dest_loc)

Handles players exiting from moving vehicles.

Definition at line 5410 of file game.cpp.

5411{
5412 const optional_vpart_position vp = m.veh_at( u.pos() );
5413 if( !vp ) {
5414 debugmsg( "Tried to exit non-existent vehicle." );
5415 return;
5416 }
5417 vehicle *const veh = &vp->vehicle();
5418 if( u.pos() == dest_loc ) {
5419 debugmsg( "Need somewhere to dismount towards." );
5420 return;
5421 }
5422 tileray ray( dest_loc.xy() + point( -u.posx(), -u.posy() ) );
5423 // TODO:: make dir() const correct!
5424 const units::angle d = ray.dir();
5425 add_msg( _( "You dive from the %s." ), veh->name );
5426 m.unboard_vehicle( u.pos() );
5427 u.moves -= 200;
5428 // Dive three tiles in the direction of tox and toy
5429 fling_creature( &u, d, 30, true );
5430 // Hit the ground according to vehicle speed
5431 if( !m.has_flag( "SWIMMABLE", u.pos() ) ) {
5432 if( veh->velocity > 0 ) {
5433 fling_creature( &u, veh->face.dir(), veh->velocity / static_cast<float>( 100 ) );
5434 } else {
5435 fling_creature( &u, veh->face.dir() + 180_degrees,
5436 -( veh->velocity ) / static_cast<float>( 100 ) );
5437 }
5438 }
5439}
void fling_creature(Creature *c, const units::angle &dir, float flvel, bool controlled=false, bool suppress_map_update=false)
Flings the input creature in the given direction.
Definition: game.cpp:10305

References _, add_msg(), debugmsg, tileray::dir(), vehicle::face, fling_creature(), map::has_flag(), m, Creature::moves, vehicle::name, Character::pos(), Character::posx(), Character::posy(), u, map::unboard_vehicle(), map::veh_at(), vehicle::velocity, and tripoint::xy().

◆ natural_light_level()

float game::natural_light_level ( int  zlev) const

Definition at line 3853 of file game.cpp.

3854{
3855 // ignore while underground or above limits
3856 if( zlev > OVERMAP_HEIGHT || zlev < 0 ) {
3857 return LIGHT_AMBIENT_MINIMAL;
3858 }
3859
3860 if( latest_lightlevels[zlev] > -std::numeric_limits<float>::max() ) {
3861 // Already found the light level for now?
3862 return latest_lightlevels[zlev];
3863 }
3864
3865 float ret = LIGHT_AMBIENT_MINIMAL;
3866
3867 // Sunlight/moonlight related stuff
3869 if( !weather.lightning_active ) {
3871 } else {
3872 // Recent lightning strike has lit the area
3874 }
3875
3877
3878 // Artifact light level changes here. Even though some of these only have an effect
3879 // aboveground it is cheaper performance wise to simply iterate through the entire
3880 // list once instead of twice.
3881 float mod_ret = -1;
3882 // Each artifact change does std::max(mod_ret, new val) since a brighter end value
3883 // will trump a lower one.
3884 if( const timed_event *e = timed_events.get( TIMED_EVENT_DIM ) ) {
3885 // TIMED_EVENT_DIM slowly dims the natural sky level, then relights it.
3886 const time_duration left = e->when - calendar::turn;
3887 // TIMED_EVENT_DIM has an occurrence date of turn + 50, so the first 25 dim it,
3888 if( left > 25_turns ) {
3889 mod_ret = std::max( static_cast<double>( mod_ret ), ( ret * ( left - 25_turns ) ) / 25_turns );
3890 // and the last 25 scale back towards normal.
3891 } else {
3892 mod_ret = std::max( static_cast<double>( mod_ret ), ( ret * ( 25_turns - left ) ) / 25_turns );
3893 }
3894 }
3896 // TIMED_EVENT_ARTIFACT_LIGHT causes everywhere to become as bright as day.
3897 mod_ret = std::max<float>( ret, default_daylight_level() );
3898 }
3899 // If we had a changed light level due to an artifact event then it overwrites
3900 // the natural light level.
3901 if( mod_ret > -1 ) {
3902 ret = mod_ret;
3903 }
3904
3905 // Cap everything to our minimum light level
3906 ret = std::max<float>( LIGHT_AMBIENT_MINIMAL, ret );
3907
3908 latest_lightlevels[zlev] = ret;
3909
3910 return ret;
3911}
double default_daylight_level()
How much light is provided in full daylight.
Definition: calendar.cpp:62
float sunlight(const time_point &p, const bool vision)
Returns the current sunlight or moonlight level through the preceding functions.
Definition: calendar.cpp:199
std::array< float, OVERMAP_LAYERS > latest_lightlevels
Definition: game.h:1090
bool queued(timed_event_type type) const
timed_event * get(timed_event_type type)
weather_type_id weather_id
Definition: weather.h:193
static constexpr float LIGHT_AMBIENT_MINIMAL
Definition: lightmap.h:12
@ TIMED_EVENT_DIM
Definition: timed_event.h:22
@ TIMED_EVENT_ARTIFACT_LIGHT
Definition: timed_event.h:23

References default_daylight_level(), timed_event_manager::get(), get_weather, latest_lightlevels, left, LIGHT_AMBIENT_MINIMAL, weather_type::light_modifier, OVERMAP_HEIGHT, timed_event_manager::queued(), cata::hash64_detail::ret, sunlight(), TIMED_EVENT_ARTIFACT_LIGHT, TIMED_EVENT_DIM, timed_events, calendar::turn, and weather_manager::weather_id.

Referenced by light_level().

◆ npc_menu()

bool game::npc_menu ( npc who)

Returns true if the menu handled stuff and player shouldn't do anything else.

Perception slightly increases precision when examining NPCs' wounds Firstaid increases precision when examining NPCs' wounds

Definition at line 5541 of file game.cpp.

5542{
5543 enum choices : int {
5544 talk = 0,
5545 swap_pos,
5546 push,
5547 examine_wounds,
5548 use_item,
5549 sort_armor,
5550 attack,
5551 disarm,
5552 steal
5553 };
5554
5555 const bool obeys = debug_mode || ( who.is_player_ally() && !who.in_sleep_state() );
5556
5557 uilist amenu;
5558
5559 amenu.text = string_format( _( "What to do with %s?" ), who.disp_name() );
5560 amenu.addentry( talk, true, 't', _( "Talk" ) );
5561 amenu.addentry( swap_pos, obeys && !who.is_mounted() &&
5562 !u.is_mounted(), 's', _( "Swap positions" ) );
5563 amenu.addentry( push, obeys && !who.is_mounted(), 'p', _( "Push away" ) );
5564 amenu.addentry( examine_wounds, true, 'w', _( "Examine wounds" ) );
5565 amenu.addentry( use_item, true, 'i', _( "Use item on" ) );
5566 amenu.addentry( sort_armor, true, 'r', _( "Sort armor" ) );
5567 amenu.addentry( attack, true, 'a', _( "Attack" ) );
5568 if( !who.is_player_ally() ) {
5569 amenu.addentry( disarm, who.is_armed(), 'd', _( "Disarm" ) );
5570 amenu.addentry( steal, !who.is_enemy(), 'S', _( "Steal" ) );
5571 }
5572
5573 amenu.query();
5574
5575 const int choice = amenu.ret;
5576 if( choice == talk ) {
5577 who.talk_to_u();
5578 } else if( choice == swap_pos ) {
5579 if( !prompt_dangerous_tile( who.pos() ) ) {
5580 return true;
5581 }
5582 // TODO: Make NPCs protest when displaced onto dangerous crap
5583 add_msg( _( "You swap places with %s." ), who.name );
5584 swap_critters( u, who );
5585 // TODO: Make that depend on stuff
5586 u.mod_moves( -200 );
5587 } else if( choice == push ) {
5588 // TODO: Make NPCs protest when displaced onto dangerous crap
5589 tripoint oldpos = who.pos();
5590 who.move_away_from( u.pos(), true );
5591 u.mod_moves( -20 );
5592 if( oldpos != who.pos() ) {
5593 add_msg( _( "%s moves out of the way." ), who.name );
5594 } else {
5595 add_msg( m_warning, _( "%s has nowhere to go!" ), who.name );
5596 }
5597 } else if( choice == examine_wounds ) {
5598 ///\EFFECT_PER slightly increases precision when examining NPCs' wounds
5599
5600 ///\EFFECT_FIRSTAID increases precision when examining NPCs' wounds
5601 const bool precise = u.get_skill_level( skill_firstaid ) * 4 + u.per_cur >= 20;
5602 who.body_window( _( "Limbs of: " ) + who.disp_name(), true, precise, 0, 0, 0, 0.0f, 0.0f, 0.0f,
5603 0.0f, 0.0f );
5604 } else if( choice == use_item ) {
5605 static const std::string heal_string( "heal" );
5606 const auto will_accept = []( const item & it ) {
5607 const auto use_fun = it.get_use( heal_string );
5608 if( use_fun == nullptr ) {
5609 return false;
5610 }
5611
5612 const auto *actor = dynamic_cast<const heal_actor *>( use_fun->get_actor_ptr() );
5613
5614 return actor != nullptr &&
5615 actor->limb_power >= 0 &&
5616 actor->head_power >= 0 &&
5617 actor->torso_power >= 0;
5618 };
5619 item_location loc = game_menus::inv::titled_filter_menu( will_accept, u, _( "Use which item?" ) );
5620
5621 if( !loc ) {
5622 add_msg( _( "Never mind" ) );
5623 return false;
5624 }
5625 item &used = *loc;
5626 bool did_use = u.invoke_item( &used, heal_string, who.pos() );
5627 if( did_use ) {
5628 // Note: exiting a body part selection menu counts as use here
5629 u.mod_moves( -300 );
5630 }
5631 } else if( choice == sort_armor ) {
5632 who.sort_armor();
5633 u.mod_moves( -100 );
5634 } else if( choice == attack ) {
5635 if( who.is_enemy() || query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5636 u.melee_attack( who, true );
5637 who.on_attacked( u );
5638 }
5639 } else if( choice == disarm ) {
5640 if( who.is_enemy() || query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5641 u.disarm( who );
5642 }
5643 } else if( choice == steal && query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5644 u.steal( who );
5645 }
5646
5647 return true;
5648}
hp_part body_window(const std::string &menu_header, bool show_all, bool precise, int normal_bonus, int head_bonus, int torso_bonus, float bleed, float bite, float infect, float bandage_power, float disinfectant_power) const
Displays menu with body part hp, optionally with hp estimation after healing.
Definition: character.cpp:5720
bool in_sleep_state() const override
Definition: character.cpp:9152
void melee_attack(Creature &t, bool allow_special, const matec_id &force_technique, bool allow_unarmed=true)
Sets up a melee attack and handles melee attack function calls.
Definition: melee.cpp:390
int per_cur
Definition: character.h:307
void steal(npc &target)
Try to steal an item from the NPC's inventory.
Definition: melee.cpp:2340
bool prompt_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:9246
bool swap_critters(Creature &, Creature &)
Swaps positions of two creatures.
Definition: game.cpp:5067
float limb_power
How much hp to restore when healing limbs?
Definition: iuse_actor.h:972
void talk_to_u(bool radio_contact=false)
Definition: npctalk.cpp:730
void on_attacked(const Creature &attacker)
Definition: npc.cpp:1446
void move_away_from(const tripoint &p, bool no_bash_atk=false, std::set< tripoint > *nomove=nullptr)
Definition: npcmove.cpp:2516
void disarm(npc &target)
Try to disarm the NPC.
Definition: melee.cpp:2264
static const skill_id skill_firstaid("firstaid")
static void swap_pos(Creature &caster, const tripoint &target)
item_location steal(avatar &you, player &victim)
Menu for stealing stuff.
item_location titled_filter_menu(item_filter filter, avatar &you, const std::string &title, const std::string &none_message="")
void push(monster &z)
Definition: monexamine.cpp:552

References _, add_msg(), uilist::addentry(), Character::body_window(), debug_mode, player::disarm(), Character::disp_name(), Character::get_skill_level(), Character::in_sleep_state(), avatar::invoke_item(), Character::is_armed(), npc::is_enemy(), Character::is_mounted(), npc::is_player_ally(), heal_actor::limb_power, m_warning, Character::melee_attack(), Creature::mod_moves(), npc::move_away_from(), Character::name, npc::on_attacked(), Character::per_cur, Character::pos(), prompt_dangerous_tile(), monexamine::push(), uilist::query(), query_yn(), uilist::ret, skill_firstaid, player::sort_armor(), game_menus::inv::steal(), avatar::steal(), string_format(), swap_critters(), swap_pos(), npc::talk_to_u(), uilist::text, game_menus::inv::titled_filter_menu(), u, and avatar_action::use_item().

Referenced by examine().

◆ num_creatures()

size_t game::num_creatures ( ) const

Returns the approximate number of creatures in the reality bubble.

Because of performance restrictions it may return a slightly incorrect values (as it includes dead, but not yet cleaned up creatures).

Definition at line 5012 of file game.cpp.

5013{
5014 return critter_tracker->size() + active_npc.size() + 1; // 1 == g->u
5015}

References active_npc, and critter_tracker.

Referenced by display_visibility(), and fungal_effects::fungalize().

◆ on_move_effects()

void game::on_move_effects ( )

Definition at line 10263 of file game.cpp.

10264{
10265 // TODO: Move this to a character method
10266 if( !u.is_mounted() ) {
10267 const item muscle( "muscle" );
10268 for( const bionic_id &bid : u.get_bionic_fueled_with( muscle ) ) {
10269 if( u.has_active_bionic( bid ) ) {// active power gen
10270 u.mod_power_level( units::from_kilojoule( muscle.fuel_energy() ) * bid->fuel_efficiency );
10271 } else if( u.has_bionic( bid ) ) {// passive power gen
10272 u.mod_power_level( units::from_kilojoule( muscle.fuel_energy() ) * bid->passive_fuel_efficiency );
10273 }
10274 }
10275
10276 if( u.has_active_bionic( bionic_id( "bio_jointservo" ) ) ) {
10277 if( u.movement_mode_is( CMM_RUN ) ) {
10278 u.mod_power_level( -55_J );
10279 } else {
10280 u.mod_power_level( -35_J );
10281 }
10282 }
10283 }
10284
10285 if( u.movement_mode_is( CMM_RUN ) ) {
10286 if( !u.can_run() ) {
10288 }
10289 }
10290
10291 // apply martial art move bonuses
10292 u.martial_arts_data->ma_onmove_effects( u );
10293
10295}
@ CMM_RUN
Definition: character.h:98
bool can_run()
source of truth of whether a Character can run
Definition: character.cpp:1317
bool movement_mode_is(character_movemode mode) const
Check against the character's current movement mode.
Definition: character.cpp:1603
std::vector< bionic_id > get_bionic_fueled_with(const item &it) const
Return bionic_id of bionics able to use it as fuel.
Definition: character.cpp:1912
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1861
void do_ambient()
Definition: sounds.cpp:1607
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32

References Character::can_run(), CMM_RUN, sfx::do_ambient(), units::from_kilojoule(), item::fuel_energy(), Character::get_bionic_fueled_with(), Character::has_active_bionic(), Character::has_bionic(), Character::is_mounted(), Character::martial_arts_data, Character::mod_power_level(), Character::movement_mode_is(), avatar::toggle_run_mode(), and u.

Referenced by phasing_move(), and walk_move().

◆ on_options_changed()

void game::on_options_changed ( )

Should be invoked whenever options change.

Definition at line 10297 of file game.cpp.

10298{
10299#if defined(TILES)
10300 tilecontext->on_options_changed();
10301#endif
10302 grid_tracker_ptr->on_options_changed();
10303}

References grid_tracker_ptr.

◆ open_consume_item_menu()

void game::open_consume_item_menu ( )
private

Definition at line 1490 of file handle_action.cpp.

1491{
1492 uilist as_m;
1493
1494 as_m.text = _( "What do you want to consume?" );
1495
1496 as_m.entries.emplace_back( 0, true, 'f', _( "Food" ) );
1497 as_m.entries.emplace_back( 1, true, 'd', _( "Drink" ) );
1498 as_m.entries.emplace_back( 2, true, 'm', _( "Medication" ) );
1499 as_m.query();
1500
1501 switch( as_m.ret ) {
1502 case 0:
1504 break;
1505 case 1:
1507 break;
1508 case 2:
1510 break;
1511 default:
1512 break;
1513 }
1514}
item_location consume_drink(player &p)
Consuming a drink item via a custom menu.
item_location consume_meds(player &p)
Consuming a medication item via a custom menu.
item_location consume_food(player &p)
Consuming a food item via a custom menu.

References _, game_menus::inv::consume_drink(), game_menus::inv::consume_food(), game_menus::inv::consume_meds(), avatar_action::eat(), uilist::entries, uilist::query(), uilist::ret, uilist::text, and u.

Referenced by handle_action().

◆ open_gate()

void game::open_gate ( const tripoint p)

Definition at line 5405 of file game.cpp.

5406{
5407 gates::open_gate( p, u );
5408}
void open_gate(const tripoint &pos, player &p)
opens the gate via player's activity
Definition: gates.cpp:235

References gates::open_gate(), and u.

◆ overmap_npc_move()

void game::overmap_npc_move ( )
private

Definition at line 4521 of file game.cpp.

4522{
4523 std::vector<npc *> travelling_npcs;
4524 static constexpr int move_search_radius = 600;
4525 for( auto &elem : overmap_buffer.get_npcs_near_player( move_search_radius ) ) {
4526 if( !elem ) {
4527 continue;
4528 }
4529 npc *npc_to_add = elem.get();
4530 if( ( !npc_to_add->is_active() || rl_dist( u.pos(), npc_to_add->pos() ) > SEEX * 2 ) &&
4531 npc_to_add->mission == NPC_MISSION_TRAVELLING ) {
4532 travelling_npcs.push_back( npc_to_add );
4533 }
4534 }
4535 for( auto &elem : travelling_npcs ) {
4536 if( elem->has_omt_destination() ) {
4537 if( !elem->omt_path.empty() && rl_dist( elem->omt_path.back(), elem->global_omt_location() ) > 2 ) {
4538 //recalculate path, we got distracted doing something else probably
4539 elem->omt_path.clear();
4540 }
4541 if( elem->omt_path.empty() ) {
4542 const tripoint_abs_omt &from = elem->global_omt_location();
4543 const tripoint_abs_omt &to = elem->goal;
4544 elem->omt_path = overmap_buffer.get_travel_path( elem->global_omt_location(), elem->goal,
4546 if( elem->omt_path.empty() ) {
4547 add_msg( m_debug, "%s couldn't find overmap path from %s to %s",
4548 elem->get_name(), from.to_string(), to.to_string() );
4549 elem->goal = npc::no_goal_point;
4550 elem->mission = NPC_MISSION_NULL;
4551 }
4552 } else {
4553 if( elem->omt_path.back() == elem->global_omt_location() ) {
4554 elem->omt_path.pop_back();
4555 }
4556 // TODO: fix point types
4557 elem->travel_overmap(
4558 project_to<coords::sm>( elem->omt_path.back() ).raw() );
4559 }
4560 reload_npcs();
4561 }
4562 }
4563 return;
4564}
std::vector< tripoint_abs_omt > omt_path
Definition: character.h:1030
static constexpr tripoint_abs_omt no_goal_point
Definition: npc.h:1338
bool is_active() const
Definition: npc.cpp:2192
std::vector< tripoint_abs_omt > get_travel_path(const tripoint_abs_omt &src, const tripoint_abs_omt &dest, overmap_path_params params)
@ NPC_MISSION_NULL
Definition: npc.h:179
@ NPC_MISSION_TRAVELLING
Definition: npc.h:191
static overmap_path_params for_npc()

References add_msg(), overmap_path_params::for_npc(), overmapbuffer::get_npcs_near_player(), overmapbuffer::get_travel_path(), npc::is_active(), m_debug, npc::mission, npc::no_goal_point, NPC_MISSION_NULL, NPC_MISSION_TRAVELLING, Character::omt_path, overmap_buffer, Character::pos(), reload_npcs(), rl_dist(), SEEX, coords::coord_point< Point, Origin, Scale >::to_string(), and u.

Referenced by do_turn().

◆ peek() [1/2]

void game::peek ( )

Definition at line 5899 of file game.cpp.

5900{
5901 const cata::optional<tripoint> p = choose_direction( _( "Peek where?" ), true );
5902 if( !p ) {
5903 return;
5904 }
5905
5906 if( p->z != 0 ) {
5907 const tripoint old_pos = u.pos();
5908 vertical_move( p->z, false, true );
5909
5910 if( old_pos != u.pos() ) {
5911 look_around();
5912 vertical_move( p->z * -1, false, true );
5913 }
5914 return;
5915 }
5916
5917 if( m.impassable( u.pos() + *p ) ) {
5918 return;
5919 }
5920
5921 peek( u.pos() + *p );
5922}
cata::optional< tripoint > choose_direction(const std::string &message, const bool allow_vertical)
Request player input of a direction, possibly including vertical component.
Definition: action.cpp:964

References _, choose_direction(), map::impassable(), look_around(), m, peek(), Character::pos(), u, and vertical_move().

Referenced by handle_action(), and peek().

◆ peek() [2/2]

void game::peek ( const tripoint p)

Definition at line 5924 of file game.cpp.

5925{
5926 u.moves -= 200;
5927 tripoint prev = u.pos();
5928 u.setpos( p );
5929 tripoint center = p;
5930 const look_around_result result = look_around( /*show_window=*/true, center, center, false, false,
5931 true );
5932 u.setpos( prev );
5933
5934 if( result.peek_action && *result.peek_action == PA_BLIND_THROW ) {
5935 item_location loc;
5936 avatar_action::plthrow( u, loc, p );
5937 }
5939}

References center, map::invalidate_map_cache(), look_around(), m, Creature::moves, PA_BLIND_THROW, avatar_action::plthrow(), Character::pos(), Character::setpos(), u, and tripoint::z.

◆ perhaps_add_random_npc()

void game::perhaps_add_random_npc ( )
private

Definition at line 11570 of file game.cpp.

11571{
11572 if( !calendar::once_every( 1_hours ) ) {
11573 return;
11574 }
11575 // Create a new NPC?
11576 // Only allow NPCs on 0 z-level, otherwise they can bug out due to lack of spots
11577 if( !get_option<bool>( "RANDOM_NPC" ) || ( !m.has_zlevels() && get_levz() != 0 ) ) {
11578 return;
11579 }
11580
11581 float density = get_option<float>( "NPC_DENSITY" );
11582 static constexpr int density_search_radius = 60;
11583 const float npc_num = overmap_buffer.get_npcs_near_player( density_search_radius ).size();
11584 if( npc_num > 0.0 ) {
11585 // 100%, 80%, 64%, 52%, 41%, 33%...
11586 density *= std::pow( 0.8f, npc_num );
11587 }
11588
11589 if( !x_in_y( density, 100 ) ) {
11590 return;
11591 }
11592 bool spawn_allowed = false;
11594 int counter = 0;
11595 while( !spawn_allowed ) {
11596 if( counter >= 10 ) {
11597 return;
11598 }
11599 static constexpr int radius_spawn_range = 120;
11600 const tripoint_abs_omt u_omt = u.global_omt_location();
11601 spawn_point = u_omt + point( rng( -radius_spawn_range, radius_spawn_range ),
11602 rng( -radius_spawn_range, radius_spawn_range ) );
11603 spawn_point.z() = 0;
11604 const oter_id oter = overmap_buffer.ter( spawn_point );
11605 // shouldn't spawn on lakes or rivers.
11606 if( !is_river_or_lake( oter ) ) {
11607 spawn_allowed = true;
11608 }
11609 counter += 1;
11610 }
11611 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
11612 tmp->normalize();
11613 tmp->randomize();
11614 std::string new_fac_id = "solo_";
11615 new_fac_id += tmp->name;
11616 // create a new "lone wolf" faction for this one NPC
11617 faction *new_solo_fac = faction_manager_ptr->add_new_faction( tmp->name, faction_id( new_fac_id ),
11618 faction_id( "no_faction" ) );
11619 tmp->set_fac( new_solo_fac ? new_solo_fac->id : faction_id( "no_faction" ) );
11620 // adds the npc to the correct overmap.
11621 // Only spawn random NPCs on z-level 0
11622 // TODO: fix point types
11623 tripoint submap_spawn = omt_to_sm_copy( spawn_point.raw() );
11624 tmp->spawn_at_sm( tripoint( submap_spawn.xy(), 0 ) );
11626 tmp->form_opinion( u );
11627 tmp->mission = NPC_MISSION_NULL;
11628 tmp->long_term_goal_action();
11629 tmp->add_new_mission( mission::reserve_random( ORIGIN_ANY_NPC, tmp->global_omt_location(),
11630 tmp->getID() ) );
11631 // This will make the new NPC active- if its nearby to the player
11632 load_npcs();
11633}
faction_id id
Definition: faction.h:82
point omt_to_sm_copy(const point &p)
@ ORIGIN_ANY_NPC
Definition: mission.h:47
bool is_river_or_lake(const oter_id &ter)
Definition: overmap.cpp:505

References faction_manager_ptr, get_levz(), overmapbuffer::get_npcs_near_player(), Character::global_omt_location(), map::has_zlevels(), faction_template::id, overmapbuffer::insert_npc(), is_river_or_lake(), load_npcs(), m, NPC_MISSION_NULL, omt_to_sm_copy(), calendar::once_every(), ORIGIN_ANY_NPC, overmap_buffer, mission::reserve_random(), rng(), overmapbuffer::ter(), u, x_in_y(), and tripoint::xy().

Referenced by do_turn().

◆ phasing_move()

bool game::phasing_move ( const tripoint dest,
bool  via_ramp = false 
)

Definition at line 9995 of file game.cpp.

9996{
9997 if( dest_loc.z != u.posz() && !via_ramp ) {
9998 // No vertical phasing yet
9999 return false;
10000 }
10001
10002 //probability travel through walls but not water
10003 tripoint dest = dest_loc;
10004 // tile is impassable
10005 int tunneldist = 0;
10006 const point d( sgn( dest.x - u.posx() ), sgn( dest.y - u.posy() ) );
10007 while( m.impassable( dest ) ||
10008 ( critter_at( dest ) != nullptr && tunneldist > 0 ) ) {
10009 //add 1 to tunnel distance for each impassable tile in the line
10010 tunneldist += 1;
10011 //Being dimensionally anchored prevents quantum shenanigans.
10012 if( u.worn_with_flag( "DIMENSIONAL_ANCHOR" ) || u.has_effect_with_flag( "DIMENSIONAL_ANCHOR" ) ) {
10014 _( "You try to quantum tunnel through the barrier, but something holds you back!" ) );
10015 return false;
10016 }
10017
10018 if( tunneldist > 24 ) {
10019 add_msg( m_info, _( "It's too dangerous to tunnel that far!" ) );
10020 return false;
10021 }
10022
10023 dest.x += d.x;
10024 dest.y += d.y;
10025 }
10026
10027 if( tunneldist != 0 ) {
10028 if( ( tunneldist - 1 ) * 100_kJ
10029 > //The first 100 was already taken up by the bionic's activation cost.
10030 u.get_power_level() ) { //oops, not enough energy! Tunneling costs 100 bionic power per impassable tile
10031 if( tunneldist * 100_kJ >
10033 add_msg( _( "You try to quantum tunnel through the barrier but bounce off! You don't have enough bionic power capacity to travel that far." ) );
10034 } else {
10035 add_msg( _( "You try to quantum tunnel through the barrier but are reflected! You need %i bionic power to travel that thickness of material." ),
10036 ( 100 * tunneldist ) );
10037 }
10038 return false;
10039 }
10040
10041 if( u.in_vehicle ) {
10042 m.unboard_vehicle( u.pos() );
10043 }
10044
10045 add_msg( _( "You quantum tunnel through the %d-tile wide barrier!" ), tunneldist );
10046 //tunneling costs 100 bionic power per impassable tile, but the first 100 was already drained by activation.
10047 u.mod_power_level( -( ( tunneldist - 1 ) * 100_kJ ) );
10048 //tunneling costs 100 moves baseline, 50 per extra tile up to a cap of 500 moves
10049 u.moves -= ( 50 + ( tunneldist * 50 ) );
10050 u.setpos( dest );
10051
10052 if( m.veh_at( u.pos() ).part_with_feature( "BOARDABLE", true ) ) {
10053 m.board_vehicle( u.pos(), &u );
10054 }
10055
10056 u.grab( OBJECT_NONE );
10058 m.creature_on_trap( u );
10059 return true;
10060 }
10061
10062 return false;
10063}
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3139
units::energy get_max_power_level() const
Definition: character.cpp:1956
bool has_effect_with_flag(const std::string &flag, body_part bp=num_bp) const
Check if creature has any effect with the given flag.
Definition: creature.cpp:1195
void on_move_effects()
Definition: game.cpp:10263
void board_vehicle(const tripoint &p, player *pl)
Definition: map.cpp:1028
constexpr int sgn(const T x)
Definition: enums.h:8

References _, add_msg(), player::add_msg_if_player(), map::board_vehicle(), map::creature_on_trap(), critter_at(), Character::get_max_power_level(), Character::get_power_level(), avatar::grab(), Creature::has_effect_with_flag(), map::impassable(), Character::in_vehicle, m, m_info, Character::mod_power_level(), Creature::moves, OBJECT_NONE, on_move_effects(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), Character::setpos(), sgn(), u, map::unboard_vehicle(), map::veh_at(), Character::worn_with_flag(), point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

◆ pickup() [1/2]

void game::pickup ( )
private

Definition at line 5870 of file game.cpp.

5871{
5872 const cata::optional<tripoint> examp_ = choose_adjacent_highlight( _( "Pickup where?" ),
5873 _( "There is nothing to pick up nearby." ),
5874 ACTION_PICKUP, false );
5875 if( !examp_ ) {
5876 return;
5877 }
5878 pickup( *examp_ );
5879}

References _, ACTION_PICKUP, choose_adjacent_highlight(), and pickup().

Referenced by handle_action(), and pickup().

◆ pickup() [2/2]

void game::pickup ( const tripoint p)
private

Definition at line 5881 of file game.cpp.

5882{
5883 // Highlight target
5884 shared_ptr_fast<game::draw_callback_t> hilite_cb = make_shared_fast<game::draw_callback_t>( [&]() {
5885 m.drawsq( w_terrain, p, drawsq_params().highlight( true ) );
5886 } );
5887 add_draw_callback( hilite_cb );
5888
5889 pickup::pick_up( p, 0 );
5890}

References add_draw_callback(), map::drawsq(), m, pickup::pick_up(), and w_terrain.

◆ pickup_feet()

void game::pickup_feet ( )
private

Definition at line 5892 of file game.cpp.

5893{
5894 pickup::pick_up( u.pos(), 1 );
5895}

References pickup::pick_up(), Character::pos(), and u.

Referenced by handle_action().

◆ place_critter_around() [1/2]

monster * game::place_critter_around ( const mtype_id id,
const tripoint center,
int  radius 
)

Definition at line 4960 of file game.cpp.

4961{
4962 // TODO: change this into an assert, it must never happen.
4963 if( id.is_null() ) {
4964 return nullptr;
4965 }
4966 return place_critter_around( make_shared_fast<monster>( id ), center, radius );
4967}
monster * place_critter_around(const mtype_id &id, const tripoint &center, int radius)
Definition: game.cpp:4960

References center, and place_critter_around().

Referenced by place_critter_around(), place_critter_at(), replace_stair_monsters(), and start_game().

◆ place_critter_around() [2/2]

monster * game::place_critter_around ( const shared_ptr_fast< monster > &  mon,
const tripoint center,
int  radius,
bool  forced = false 
)

Definition at line 4969 of file game.cpp.

4973{
4975 if( forced || can_place_monster( *mon, center ) ) {
4976 where = center;
4977 }
4978
4979 // This loop ensures the monster is placed as close to the center as possible,
4980 // but all places that equally far from the center have the same probability.
4981 for( int r = 1; r <= radius && !where; ++r ) {
4983 }
4984
4985 if( !where ) {
4986 return nullptr;
4987 }
4988 mon->spawn( *where );
4989 return critter_tracker->add( mon ) ? mon.get() : nullptr;
4990}
static cata::optional< tripoint > choose_where_to_place_monster(const monster &mon, const tripoint_range< tripoint > &range)
Definition: game.cpp:4942
static bool can_place_monster(const monster &mon, const tripoint &p)
Definition: game.cpp:4926

References can_place_monster(), center, choose_where_to_place_monster(), critter_tracker, m, and map::points_in_radius().

◆ place_critter_at() [1/2]

monster * game::place_critter_at ( const mtype_id id,
const tripoint p 
)

Adds critters to the reality bubble, creating them if necessary.

Functions taking a id parameter will construct a monster based on that id, (with default properties). Functions taking a mon parameter will use the supplied monster instance instead (which must not be null). Note: the monster will not be upgraded by these functions, it is placed as is.

place_critter_at will place the creature exactly at the given point.

place_critter_around will place the creature around the center p within the given radius (radius 0 means only the center point is used). The chosen point will be as close to the center as possible.

place_critter_within will place the creature at a random point within that given range. (All points within have equal probability.)

Returns
All functions return null if the creature could not be placed (usually because the target is not suitable for it: may be a solid wall, or air, or already occupied by some creature). If the creature has been placed, it returns a pointer to it (which is the same as the one contained in mon).

Definition at line 4950 of file game.cpp.

4951{
4952 return place_critter_around( id, p, 0 );
4953}

References place_critter_around().

Referenced by fungal_effects::fungalize(), revive_corpse(), fungal_effects::spread_fungus_one_tile(), and update_stair_monsters().

◆ place_critter_at() [2/2]

monster * game::place_critter_at ( const shared_ptr_fast< monster > &  mon,
const tripoint p 
)

Definition at line 4955 of file game.cpp.

4956{
4957 return place_critter_around( mon, p, 0 );
4958}

References place_critter_around().

◆ place_critter_within() [1/2]

monster * game::place_critter_within ( const mtype_id id,
const tripoint_range< tripoint > &  range 
)

Definition at line 4992 of file game.cpp.

4993{
4994 // TODO: change this into an assert, it must never happen.
4995 if( id.is_null() ) {
4996 return nullptr;
4997 }
4998 return place_critter_within( make_shared_fast<monster>( id ), range );
4999}
monster * place_critter_within(const mtype_id &id, const tripoint_range< tripoint > &range)
Definition: game.cpp:4992

References place_critter_within().

Referenced by place_critter_within().

◆ place_critter_within() [2/2]

monster * game::place_critter_within ( const shared_ptr_fast< monster > &  mon,
const tripoint_range< tripoint > &  range 
)

Definition at line 5001 of file game.cpp.

5003{
5004 const cata::optional<tripoint> where = choose_where_to_place_monster( *mon, range );
5005 if( !where ) {
5006 return nullptr;
5007 }
5008 mon->spawn( *where );
5009 return critter_tracker->add( mon ) ? mon.get() : nullptr;
5010}

References choose_where_to_place_monster(), and critter_tracker.

◆ place_player()

point game::place_player ( const tripoint dest)
Dexterity increases chance of avoiding cuts on sharp terrain

Definition at line 9634 of file game.cpp.

9635{
9636 const optional_vpart_position vp1 = m.veh_at( dest_loc );
9637 if( const cata::optional<std::string> label = vp1.get_label() ) {
9638 add_msg( m_info, _( "Label here: %s" ), *label );
9639 }
9640 std::string signage = m.get_signage( dest_loc );
9641 if( !signage.empty() ) {
9642 if( !u.has_trait( trait_ILLITERATE ) ) {
9643 add_msg( m_info, _( "The sign says: %s" ), signage );
9644 } else {
9645 add_msg( m_info, _( "There is a sign here, but you are unable to read it." ) );
9646 }
9647 }
9648 if( m.has_graffiti_at( dest_loc ) ) {
9649 if( !u.has_trait( trait_ILLITERATE ) ) {
9650 add_msg( m_info, _( "Written here: %s" ), m.graffiti_at( dest_loc ) );
9651 } else {
9652 add_msg( m_info, _( "Something is written here, but you are unable to read it." ) );
9653 }
9654 }
9655 // TODO: Move the stuff below to a Character method so that NPCs can reuse it
9656 if( m.has_flag( "ROUGH", dest_loc ) && ( !u.in_vehicle ) && ( !u.is_mounted() ) ) {
9657 if( one_in( 5 ) && u.get_armor_bash( bodypart_id( "foot_l" ) ) < rng( 2, 5 ) ) {
9658 add_msg( m_bad, _( "You hurt your left foot on the %s!" ),
9659 m.has_flag_ter( "ROUGH", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9660 dest_loc ) );
9661 u.deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 1 ) );
9662 }
9663 if( one_in( 5 ) && u.get_armor_bash( bodypart_id( "foot_r" ) ) < rng( 2, 5 ) ) {
9664 add_msg( m_bad, _( "You hurt your right foot on the %s!" ),
9665 m.has_flag_ter( "ROUGH", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9666 dest_loc ) );
9667 u.deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 1 ) );
9668 }
9669 }
9670 ///\EFFECT_DEX increases chance of avoiding cuts on sharp terrain
9671 if( m.has_flag( "SHARP", dest_loc ) && !one_in( 3 ) && !x_in_y( 1 + u.dex_cur / 2.0, 40 ) &&
9672 ( !u.in_vehicle && !g->m.veh_at( dest_loc ) ) && ( !u.has_trait( trait_PARKOUR ) ||
9673 one_in( 4 ) ) && ( u.has_trait( trait_THICKSKIN ) ? !one_in( 8 ) : true ) ) {
9674 if( u.is_mounted() ) {
9675 add_msg( _( "Your %s gets cut!" ), u.mounted_creature->get_name() );
9676 u.mounted_creature->apply_damage( nullptr, bodypart_id( "torso" ), rng( 1, 10 ) );
9677 } else {
9678 const bodypart_id bp = u.get_random_body_part();
9679 if( u.deal_damage( nullptr, bp, damage_instance( DT_CUT, rng( 1, 10 ) ) ).total_damage() > 0 ) {
9680 //~ 1$s - bodypart name in accusative, 2$s is terrain name.
9681 add_msg( m_bad, _( "You cut your %1$s on the %2$s!" ),
9682 body_part_name_accusative( bp->token ),
9683 m.has_flag_ter( "SHARP", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9684 dest_loc ) );
9685 }
9686 }
9687 }
9688 if( m.has_flag( "UNSTABLE", dest_loc ) && !u.is_mounted() ) {
9689 u.add_effect( effect_bouldering, 1_turns, num_bp );
9690 } else if( u.has_effect( effect_bouldering ) ) {
9692 }
9693 if( m.has_flag_ter_or_furn( TFLAG_NO_SIGHT, dest_loc ) ) {
9694 u.add_effect( effect_no_sight, 1_turns, num_bp );
9695 } else if( u.has_effect( effect_no_sight ) ) {
9697 }
9698
9699 // If we moved out of the nonant, we need update our map data
9700 if( m.has_flag( "SWIMMABLE", dest_loc ) && u.has_effect( effect_onfire ) ) {
9701 add_msg( _( "The water puts out the flames!" ) );
9703 if( u.is_mounted() ) {
9704 monster *mon = u.mounted_creature.get();
9705 if( mon->has_effect( effect_onfire ) ) {
9707 }
9708 }
9709 }
9710
9711 if( monster *const mon_ptr = critter_at<monster>( dest_loc ) ) {
9712 // We displaced a monster. It's probably a bug if it wasn't a friendly mon...
9713 // Immobile monsters can't be displaced.
9714 monster &critter = *mon_ptr;
9715 // TODO: handling for ridden creatures other than players mount.
9716 if( !critter.has_effect( effect_ridden ) ) {
9717 if( u.is_mounted() ) {
9718 std::vector<tripoint> valid;
9719 for( const tripoint &jk : g->m.points_in_radius( critter.pos(), 1 ) ) {
9720 if( is_empty( jk ) ) {
9721 valid.push_back( jk );
9722 }
9723 }
9724 if( !valid.empty() ) {
9725 critter.move_to( random_entry( valid ) );
9726 add_msg( _( "You push the %s out of the way." ), critter.name() );
9727 } else {
9728 add_msg( _( "There is no room to push the %s out of the way." ), critter.name() );
9729 return u.pos().xy();
9730 }
9731 } else {
9732 critter.move_to( u.pos(), false,
9733 true ); // Force the movement even though the player is there right now.
9734 add_msg( _( "You displace the %s." ), critter.name() );
9735 }
9736 } else if( !u.has_effect( effect_riding ) ) {
9737 add_msg( _( "You cannot move the %s out of the way." ), critter.name() );
9738 return u.pos().xy();
9739 }
9740 }
9741
9742 // If the player is in a vehicle, unboard them from the current part
9743 if( u.in_vehicle ) {
9744 m.unboard_vehicle( u.pos() );
9745 }
9746 // Move the player
9747 // Start with z-level, to make it less likely that old functions (2D ones) freak out
9748 if( m.has_zlevels() && dest_loc.z != get_levz() ) {
9749 vertical_shift( dest_loc.z );
9750 }
9751
9752 if( u.is_hauling() && ( !m.can_put_items( dest_loc ) ||
9753 m.has_flag( TFLAG_DEEP_WATER, dest_loc ) ||
9754 vp1 ) ) {
9755 u.stop_hauling();
9756 }
9757 u.setpos( dest_loc );
9758 if( u.is_mounted() ) {
9759 monster *mon = u.mounted_creature.get();
9760 mon->setpos( dest_loc );
9761 mon->process_triggers();
9762 m.creature_in_field( *mon );
9763 }
9764 point submap_shift = update_map( u );
9765 // Important: don't use dest_loc after this line. `update_map` may have shifted the map
9766 // and dest_loc was not adjusted and therefore is still in the un-shifted system and probably wrong.
9767 // If you must use it you can calculate the position in the new, shifted system with
9768 // adjusted_pos = ( old_pos.x - submap_shift.x * SEEX, old_pos.y - submap_shift.y * SEEY, old_pos.z )
9769
9770 //Auto pulp or butcher and Auto foraging
9771 if( get_option<bool>( "AUTO_FEATURES" ) && mostseen == 0 && !u.is_mounted() ) {
9773
9774 const std::string forage_type = get_option<std::string>( "AUTO_FORAGING" );
9775 if( forage_type != "off" ) {
9776 const auto forage = [&]( const tripoint & pos ) {
9777 const auto &xter_t = m.ter( pos ).obj().examine;
9778 const auto &xfurn_t = m.furn( pos ).obj().examine;
9779 const bool forage_everything = forage_type == "both";
9780 const bool forage_bushes = forage_everything || forage_type == "bushes";
9781 const bool forage_trees = forage_everything || forage_type == "trees";
9782 if( xter_t == &iexamine::none ) {
9783 return;
9784 } else if( ( forage_bushes && xter_t == &iexamine::shrub_marloss ) ||
9785 ( forage_bushes && xter_t == &iexamine::shrub_wildveggies ) ||
9786 ( forage_bushes && xter_t == &iexamine::harvest_ter_nectar ) ||
9787 ( forage_trees && xter_t == &iexamine::tree_marloss ) ||
9788 ( forage_trees && xter_t == &iexamine::harvest_ter ) ||
9789 ( forage_trees && xter_t == &iexamine::harvest_ter_nectar )
9790 ) {
9791 xter_t( u, pos );
9792 } else if( ( forage_everything && xfurn_t == &iexamine::harvest_furn ) ||
9793 ( forage_everything && xfurn_t == &iexamine::harvest_furn_nectar )
9794 ) {
9795 xfurn_t( u, pos );
9796 }
9797 };
9798
9799 for( auto &elem : adjacentDir ) {
9800 forage( u.pos() + direction_XY( elem ) );
9801 }
9802 }
9803
9804 const std::string pulp_butcher = get_option<std::string>( "AUTO_PULP_BUTCHER" );
9805 if( pulp_butcher == "butcher" && u.max_quality( quality_id( "BUTCHER" ) ) > INT_MIN ) {
9806 std::vector<item *> corpses;
9807
9808 for( item &it : m.i_at( u.pos() ) ) {
9809 corpses.push_back( &it );
9810 }
9811
9812 if( !corpses.empty() ) {
9813 u.assign_activity( activity_id( "ACT_BUTCHER" ), 0, true );
9814 for( item *it : corpses ) {
9815 u.activity.targets.emplace_back( map_cursor( u.pos() ), it );
9816 }
9817 }
9818 } else if( pulp_butcher == "pulp" || pulp_butcher == "pulp_adjacent" ) {
9819 const auto pulp = [&]( const tripoint & pos ) {
9820 for( const auto &maybe_corpse : m.i_at( pos ) ) {
9821 if( maybe_corpse.is_corpse() && maybe_corpse.can_revive() &&
9822 !maybe_corpse.get_mtype()->bloodType().obj().has_acid ) {
9824 u.activity.placement = g->m.getabs( pos );
9825 u.activity.auto_resume = true;
9826 u.activity.str_values.push_back( "auto_pulp_no_acid" );
9827 return;
9828 }
9829 }
9830 };
9831
9832 if( pulp_butcher == "pulp_adjacent" ) {
9833 for( auto &elem : adjacentDir ) {
9834 pulp( u.pos() + direction_XY( elem ) );
9835 }
9836 } else {
9837 pulp( u.pos() );
9838 }
9839 }
9840 }
9841
9842 //Autopickup
9843 if( !u.is_mounted() && get_option<bool>( "AUTO_PICKUP" ) && !u.is_hauling() &&
9844 ( !get_option<bool>( "AUTO_PICKUP_SAFEMODE" ) || mostseen == 0 ) &&
9845 ( m.has_items( u.pos() ) || get_option<bool>( "AUTO_PICKUP_ADJACENT" ) ) ) {
9846 pickup::pick_up( u.pos(), -1 );
9847 }
9848
9849 // If the new tile is a boardable part, board it
9850 if( vp1.part_with_feature( "BOARDABLE", true ) && !u.is_mounted() ) {
9851 m.board_vehicle( u.pos(), &u );
9852 }
9853
9854 // Traps!
9855 // Try to detect.
9857 if( u.is_mounted() ) {
9859 } else {
9860 m.creature_on_trap( u );
9861 }
9862 // Drench the player if swimmable
9863 if( m.has_flag( "SWIMMABLE", u.pos() ) &&
9864 !( u.is_mounted() || ( u.in_vehicle && vp1->vehicle().can_float() ) ) ) {
9865 u.drench( 40, { { bp_foot_l, bp_foot_r, bp_leg_l, bp_leg_r } }, false );
9866 }
9867
9868 // List items here
9869 if( !m.has_flag( "SEALED", u.pos() ) ) {
9870 if( get_option<bool>( "NO_AUTO_PICKUP_ZONES_LIST_ITEMS" ) ||
9871 !g->check_zone( zone_type_id( "NO_AUTO_PICKUP" ), u.pos() ) ) {
9872 if( u.is_blind() && !m.i_at( u.pos() ).empty() ) {
9873 add_msg( _( "There's something here, but you can't see what it is." ) );
9874 } else if( m.has_items( u.pos() ) ) {
9875 std::vector<std::string> names;
9876 std::vector<size_t> counts;
9877 std::vector<item> items;
9878 for( auto &tmpitem : m.i_at( u.pos() ) ) {
9879
9880 std::string next_tname = tmpitem.tname();
9881 std::string next_dname = tmpitem.display_name();
9882 bool by_charges = tmpitem.count_by_charges();
9883 bool got_it = false;
9884 for( size_t i = 0; i < names.size(); ++i ) {
9885 if( by_charges && next_tname == names[i] ) {
9886 counts[i] += tmpitem.charges;
9887 got_it = true;
9888 break;
9889 } else if( next_dname == names[i] ) {
9890 counts[i] += 1;
9891 got_it = true;
9892 break;
9893 }
9894 }
9895 if( !got_it ) {
9896 if( by_charges ) {
9897 names.push_back( tmpitem.tname( tmpitem.charges ) );
9898 counts.push_back( tmpitem.charges );
9899 } else {
9900 names.push_back( tmpitem.display_name( 1 ) );
9901 counts.push_back( 1 );
9902 }
9903 items.push_back( tmpitem );
9904 }
9905 if( names.size() > 10 ) {
9906 break;
9907 }
9908 }
9909 for( size_t i = 0; i < names.size(); ++i ) {
9910 if( !items[i].count_by_charges() ) {
9911 names[i] = items[i].display_name( counts[i] );
9912 } else {
9913 names[i] = items[i].tname( counts[i] );
9914 }
9915 }
9916 int and_the_rest = 0;
9917 for( size_t i = 0; i < names.size(); ++i ) {
9918 //~ number of items: "<number> <item>"
9919 std::string fmt = vgettext( "%1$d %2$s", "%1$d %2$s", counts[i] );
9920 names[i] = string_format( fmt, counts[i], names[i] );
9921 // Skip the first two.
9922 if( i > 1 ) {
9923 and_the_rest += counts[i];
9924 }
9925 }
9926 if( names.size() == 1 ) {
9927 add_msg( _( "You see here %s." ), names[0] );
9928 } else if( names.size() == 2 ) {
9929 add_msg( _( "You see here %s and %s." ), names[0], names[1] );
9930 } else if( names.size() == 3 ) {
9931 add_msg( _( "You see here %s, %s, and %s." ), names[0], names[1], names[2] );
9932 } else if( and_the_rest < 7 ) {
9933 add_msg( vgettext( "You see here %s, %s and %d more item.",
9934 "You see here %s, %s and %d more items.",
9935 and_the_rest ),
9936 names[0], names[1], and_the_rest );
9937 } else {
9938 add_msg( _( "You see here %s and many more items." ), names[0] );
9939 }
9940 }
9941 }
9942 }
9943
9944 if( ( vp1.part_with_feature( "CONTROL_ANIMAL", true ) ||
9945 vp1.part_with_feature( "CONTROLS", true ) ) && u.in_vehicle && !u.is_mounted() ) {
9946 add_msg( _( "There are vehicle controls here." ) );
9947 if( !u.has_trait( trait_id( "WAYFARER" ) ) ) {
9948 add_msg( m_info, _( "%s to drive." ), press_x( ACTION_CONTROL_VEHICLE ) );
9949 }
9950 } else if( vp1.part_with_feature( "CONTROLS", true ) && u.in_vehicle &&
9951 u.is_mounted() ) {
9952 add_msg( _( "There are vehicle controls here but you cannot reach them whilst mounted." ) );
9953 }
9954 return submap_shift;
9955}
std::string body_part_name_accusative(body_part bp, int number)
Returns the matching accusative name of the body_part token, i.e.
Definition: bodypart.cpp:329
void drench(int saturation, const body_part_set &flags, bool ignore_waterproof)
Drenches the player with water, saturation is the percent gotten wet.
Definition: suffer.cpp:1755
bool is_hauling() const
Definition: character.cpp:9016
void stop_hauling()
Definition: character.cpp:9007
bodypart_id get_random_body_part(bool main=false) const
Definition: creature.cpp:1614
void vertical_shift(int z_after)
Actual z-level movement part of vertical_move.
Definition: game.cpp:11093
std::string furnname(const tripoint &p)
Definition: map.cpp:1480
bool has_flag_ter_or_furn(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2333
bool has_graffiti_at(const tripoint &p) const
Definition: map.cpp:7659
bool has_items(const tripoint &p) const
Checks for existence of items.
Definition: map.cpp:4783
const std::string & graffiti_at(const tripoint &p) const
Definition: map.cpp:7648
bool has_flag_ter(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2323
bool can_put_items(const tripoint &p) const
Definition: map.cpp:2309
void setpos(const tripoint &p) override
Definition: monster.cpp:237
bool move_to(const tripoint &p, bool force=false, bool step_on_critter=false, float stagger_adjustment=1.0)
Attempt to move to p.
Definition: monmove.cpp:1493
void process_triggers()
Definition: monster.cpp:1192
cata::optional< std::string > get_label() const
std::vector< std::string > str_values
bool auto_resume
If true, the activity will be auto-resumed next time the player attempts an identical activity.
void search_surroundings()
Search surrounding squares for traps (and maybe other things in the future).
Definition: player.cpp:848
static const efftype_id effect_riding("riding")
static const trait_id trait_ILLITERATE("ILLITERATE")
static const efftype_id effect_bouldering("bouldering")
static const trait_id trait_PARKOUR("PARKOUR")
static const efftype_id effect_no_sight("no_sight")
static const trait_id trait_THICKSKIN("THICKSKIN")
static const efftype_id effect_onfire("onfire")
point direction_XY(const direction dir)
Definition: line.cpp:433
@ TFLAG_NO_SIGHT
Definition: mapdata.h:283
@ TFLAG_DEEP_WATER
Definition: mapdata.h:301
static std::map< nameFlags, std::vector< std::string > > names
Definition: name.cpp:18
const int INDEFINITELY_LONG
A number that represents the longest possible action.
void shrub_wildveggies(player &p, const tripoint &examp)
Definition: iexamine.cpp:3607
void shrub_marloss(player &p, const tripoint &examp)
Definition: iexamine.cpp:3574
void harvest_ter(player &p, const tripoint &examp)
Definition: iexamine.cpp:2021
void harvest_furn(player &p, const tripoint &examp)
Definition: iexamine.cpp:2001
void harvest_ter_nectar(player &p, const tripoint &examp)
Definition: iexamine.cpp:2010
void harvest_furn_nectar(player &p, const tripoint &examp)
Definition: iexamine.cpp:1992
void tree_marloss(player &p, const tripoint &examp)
Definition: iexamine.cpp:3587

References _, ACTION_CONTROL_VEHICLE, Character::activity, Creature::add_effect(), add_msg(), Character::assign_activity(), player_activity::auto_resume, map::board_vehicle(), body_part_name_accusative(), bp_foot_l, bp_foot_r, bp_leg_l, bp_leg_r, map::can_put_items(), map::creature_in_field(), map::creature_on_trap(), Character::deal_damage(), Character::dex_cur, direction_XY(), Character::drench(), DT_CUT, EAST, effect_bouldering, effect_no_sight, effect_onfire, effect_ridden, effect_riding, item_stack::empty(), map_data_common_t::examine, map::furn(), map::furnname(), g, Character::get_armor_bash(), optional_vpart_position::get_label(), get_levz(), Creature::get_random_body_part(), map::get_signage(), map::graffiti_at(), iexamine::harvest_furn(), iexamine::harvest_furn_nectar(), iexamine::harvest_ter(), iexamine::harvest_ter_nectar(), Creature::has_effect(), map::has_flag(), map::has_flag_ter(), map::has_flag_ter_or_furn(), map::has_graffiti_at(), map::has_items(), Character::has_trait(), map::has_zlevels(), map::i_at(), Character::in_vehicle, calendar::INDEFINITELY_LONG, Character::is_blind(), is_empty(), Character::is_hauling(), Character::is_mounted(), m, m_bad, m_info, visitable< T >::max_quality(), mostseen, Character::mounted_creature, monster::move_to(), monster::name(), Name::names, iexamine::none(), NORTH, NORTHEAST, NORTHWEST, num_bp, int_id< T >::obj(), one_in(), optional_vpart_position::part_with_feature(), pickup::pick_up(), player_activity::placement, Character::pos(), monster::pos(), press_x(), monster::process_triggers(), random_entry(), Creature::remove_effect(), rng(), player::search_surroundings(), Character::setpos(), monster::setpos(), iexamine::shrub_marloss(), iexamine::shrub_wildveggies(), SOUTH, SOUTHEAST, SOUTHWEST, Character::stop_hauling(), player_activity::str_values, string_format(), player_activity::targets, map::ter(), map::tername(), TFLAG_DEEP_WATER, TFLAG_NO_SIGHT, trait_ILLITERATE, trait_PARKOUR, trait_THICKSKIN, iexamine::tree_marloss(), u, map::unboard_vehicle(), update_map(), map::veh_at(), vertical_shift(), vgettext(), WEST, x_in_y(), tripoint::xy(), and tripoint::z.

Referenced by place_player_overmap(), and walk_move().

◆ place_player_overmap()

void game::place_player_overmap ( const tripoint_abs_omt om_dest)

Definition at line 9957 of file game.cpp.

9958{
9959 // if player is teleporting around, they don't bring their horse with them
9960 if( u.is_mounted() ) {
9962 u.mounted_creature->remove_effect( effect_ridden );
9963 u.mounted_creature = nullptr;
9964 }
9965 // offload the active npcs.
9966 unload_npcs();
9967 for( monster &critter : all_monsters() ) {
9968 despawn_monster( critter );
9969 }
9970 if( u.in_vehicle ) {
9971 m.unboard_vehicle( u.pos() );
9972 }
9973 const int minz = m.has_zlevels() ? -OVERMAP_DEPTH : get_levz();
9974 const int maxz = m.has_zlevels() ? OVERMAP_HEIGHT : get_levz();
9975 for( int z = minz; z <= maxz; z++ ) {
9977 m.clear_vehicle_list( z );
9978 }
9980 // offset because load_map expects the coordinates of the top left corner, but the
9981 // player will be centered in the middle of the map.
9982 // TODO: fix point types
9983 const tripoint map_sm_pos(
9984 project_to<coords::sm>( om_dest ).raw() + point( -HALF_MAPSIZE, -HALF_MAPSIZE ) );
9985 const tripoint player_pos( u.pos().xy(), map_sm_pos.z );
9986 load_map( map_sm_pos );
9987 load_npcs();
9988 m.spawn_monsters( true ); // Static monsters
9990 // update weather now as it could be different on the new location
9992 place_player( player_pos );
9993}
point place_player(const tripoint &dest)
Definition: game.cpp:9634
void unload_npcs()
Unloads all NPCs.
Definition: game.cpp:948
void update_overmap_seen()
Definition: game.cpp:11271
void clear_vehicle_cache(int zlev)
Definition: map.cpp:303
level_cache & access_cache(int zlev)
Definition: map.cpp:8490
void clear_vehicle_list(int zlev)
Definition: map.cpp:317
std::bitset< MAPSIZE_X *MAPSIZE_Y > map_memory_seen_cache
Definition: map.h:339

References map::access_cache(), all_monsters(), map::clear_vehicle_cache(), map::clear_vehicle_list(), despawn_monster(), effect_ridden, effect_riding, get_levz(), get_weather, HALF_MAPSIZE, map::has_zlevels(), Character::in_vehicle, Character::is_mounted(), load_map(), load_npcs(), m, level_cache::map_memory_seen_cache, Character::mounted_creature, weather_manager::nextweather, OVERMAP_DEPTH, OVERMAP_HEIGHT, place_player(), Character::pos(), Creature::remove_effect(), map::spawn_monsters(), calendar::turn, u, map::unboard_vehicle(), unload_npcs(), update_overmap_seen(), tripoint::xy(), and tripoint::z.

◆ place_vehicle_nearby()

vehicle * game::place_vehicle_nearby ( const vproto_id id,
const point_abs_omt origin,
int  min_distance,
int  max_distance,
const std::vector< std::string > &  omt_search_types = {} 
)
private

Definition at line 844 of file game.cpp.

847{
848 std::vector<std::string> search_types = omt_search_types;
849 if( search_types.empty() ) {
850 vehicle veh( id );
851 if( veh.can_float() ) {
852 search_types.push_back( "river" );
853 search_types.push_back( "lake" );
854 } else {
855 search_types.push_back( "field" );
856 search_types.push_back( "road" );
857 }
858 }
859 for( const std::string &search_type : search_types ) {
860 omt_find_params find_params;
861 find_params.must_see = false;
862 find_params.cant_see = false;
863 find_params.types.emplace_back( search_type, ot_match_type::type );
864 // find nearest road
865 find_params.min_distance = min_distance;
866 find_params.search_range = max_distance;
867 // if player spawns underground, park their car on the surface.
868 const tripoint_abs_omt omt_origin( origin, 0 );
869 for( const tripoint_abs_omt &goal : overmap_buffer.find_all( omt_origin, find_params ) ) {
870 // try place vehicle there.
871 tinymap target_map;
872 target_map.load( project_to<coords::sm>( goal ), false );
873 const tripoint tinymap_center( SEEX, SEEY, goal.z() );
874 static constexpr std::array<units::angle, 4> angles = {{
875 0_degrees, 90_degrees, 180_degrees, 270_degrees
876 }
877 };
878 vehicle *veh = target_map.add_vehicle(
879 id, tinymap_center, random_entry( angles ), rng( 50, 80 ), 0, false );
880 if( veh ) {
881 tripoint abs_local = g->m.getlocal( target_map.getabs( tinymap_center ) );
882 veh->sm_pos = ms_to_sm_remain( abs_local );
883 veh->pos = abs_local.xy();
885 veh->tracking_on = true;
886 target_map.save();
887 return veh;
888 }
889 }
890 }
891 return nullptr;
892}
void save()
Add currently loaded submaps (in grid) to the mapbuffer.
Definition: map.cpp:6493
vehicle * add_vehicle(const vgroup_id &type, const tripoint &p, units::angle dir, int init_veh_fuel=-1, int init_veh_status=-1, bool merge_wrecks=true)
Definition: mapgen.cpp:5600
void add_vehicle(vehicle *veh)
Add the vehicle to be tracked in the overmap.
std::vector< tripoint_abs_omt > find_all(const tripoint_abs_omt &origin, const omt_find_params &params)
Find all places with the specific overmap terrain type.
Definition: map.h:2067
point pos
Position of the vehicle inside the submap that contains the vehicle.
Definition: vehicle.h:1859
tripoint sm_pos
Submap coordinates of the currently loaded submap (see game::m) that contains this vehicle.
Definition: vehicle.h:1844
bool tracking_on
Definition: vehicle.h:1932
point ms_to_sm_remain(int &x, int &y)
static constexpr int SEEY
Standard arguments for finding overmap terrain.
std::vector< std::pair< std::string, ot_match_type > > types

References map::add_vehicle(), overmapbuffer::add_vehicle(), vehicle::can_float(), omt_find_params::cant_see, overmapbuffer::find_all(), g, map::getabs(), map::load(), omt_find_params::min_distance, ms_to_sm_remain(), omt_find_params::must_see, overmap_buffer, vehicle::pos, random_entry(), rng(), map::save(), omt_find_params::search_range, SEEX, SEEY, vehicle::sm_pos, vehicle::tracking_on, type, omt_find_params::types, and tripoint::xy().

Referenced by start_game().

◆ pre_print_all_tile_info()

void game::pre_print_all_tile_info ( const tripoint lp,
const catacurses::window w_info,
int &  line,
int  last_line,
const visibility_variables cache 
)

Definition at line 6822 of file game.cpp.

6825{
6826 // get global area info according to look_around caret position
6827 // TODO: fix point types
6829 lp ) ) ) );
6830 // we only need the area name and then pass it to print_all_tile_info() function below
6831 const std::string area_name = cur_ter_m->get_name();
6832 print_all_tile_info( lp, w_info, area_name, 1, first_line, last_line, cache );
6833}
void print_all_tile_info(const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line, int last_line, const visibility_variables &cache)
Definition: game.cpp:6002
point ms_to_omt_copy(const point &p)
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493
std::string get_name() const
Definition: omdata.h:279

References oter_t::get_name(), map::getabs(), m, ms_to_omt_copy(), overmap_buffer, print_all_tile_info(), and overmapbuffer::ter().

Referenced by look_around().

◆ print_all_tile_info()

void game::print_all_tile_info ( const tripoint lp,
const catacurses::window w_look,
const std::string &  area_name,
int  column,
int &  line,
int  last_line,
const visibility_variables cache 
)

Definition at line 6002 of file game.cpp.

6007{
6008 visibility_type visibility = VIS_HIDDEN;
6009 const bool inbounds = m.inbounds( lp );
6010 if( inbounds ) {
6011 visibility = m.get_visibility( m.apparent_light_at( lp, cache ), cache );
6012 }
6013 const Creature *creature = critter_at( lp, true );
6014 switch( visibility ) {
6015 case VIS_CLEAR: {
6016 const optional_vpart_position vp = m.veh_at( lp );
6017 print_terrain_info( lp, w_look, area_name, column, line );
6018 print_fields_info( lp, w_look, column, line );
6019 print_trap_info( lp, w_look, column, line );
6020 print_creature_info( creature, w_look, column, line, last_line );
6021 print_vehicle_info( veh_pointer_or_null( vp ), vp ? vp->part_index() : -1, w_look, column, line,
6022 last_line );
6023 print_items_info( lp, w_look, column, line, last_line );
6024 print_graffiti_info( lp, w_look, column, line, last_line );
6025 }
6026 break;
6027 case VIS_BOOMER:
6028 case VIS_BOOMER_DARK:
6029 case VIS_DARK:
6030 case VIS_LIT:
6031 case VIS_HIDDEN:
6032 print_visibility_info( w_look, column, line, visibility );
6033
6034 if( creature != nullptr ) {
6035 std::vector<std::string> buf;
6036 if( u.sees_with_infrared( *creature ) ) {
6037 creature->describe_infrared( buf );
6038 } else if( u.sees_with_specials( *creature ) ) {
6039 creature->describe_specials( buf );
6040 }
6041 for( const std::string &s : buf ) {
6042 mvwprintw( w_look, point( 1, ++line ), s );
6043 }
6044 }
6045 break;
6046 }
6047 if( !inbounds ) {
6048 return;
6049 }
6050 auto this_sound = sounds::sound_at( lp );
6051 if( !this_sound.empty() ) {
6052 mvwprintw( w_look, point( 1, ++line ), _( "You heard %s from here." ), this_sound );
6053 } else {
6054 // Check other z-levels
6055 tripoint tmp = lp;
6056 for( tmp.z = -OVERMAP_DEPTH; tmp.z <= OVERMAP_HEIGHT; tmp.z++ ) {
6057 if( tmp.z == lp.z ) {
6058 continue;
6059 }
6060
6061 auto zlev_sound = sounds::sound_at( tmp );
6062 if( !zlev_sound.empty() ) {
6063 mvwprintw( w_look, point( 1, ++line ), tmp.z > lp.z ?
6064 _( "You heard %s from above." ) : _( "You heard %s from below." ), zlev_sound );
6065 }
6066 }
6067 }
6068}
bool sees_with_specials(const Creature &critter) const
Definition: character.cpp:6297
bool sees_with_infrared(const Creature &critter) const
Check whether the this player can see the other creature with infrared.
void print_fields_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line)
Definition: game.cpp:6172
void print_terrain_info(const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line)
Definition: game.cpp:6099
void print_graffiti_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:6264
void print_creature_info(const Creature *creature, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:6209
void print_vehicle_info(const vehicle *veh, int veh_part, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:6218
void print_items_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:6227
void print_visibility_info(const catacurses::window &w_look, int column, int &line, visibility_type visibility)
Definition: game.cpp:6070
void print_trap_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line)
Definition: game.cpp:6190
void line(map *m, const ter_id &type, const point &p1, const point &p2)
Definition: mapgen.cpp:6454
std::string sound_at(const tripoint &location)
Definition: sounds.cpp:605

References _, map::apparent_light_at(), creature, critter_at(), map::get_visibility(), map::inbounds(), line(), m, catacurses::mvwprintw(), OVERMAP_DEPTH, OVERMAP_HEIGHT, print_creature_info(), print_fields_info(), print_graffiti_info(), print_items_info(), print_terrain_info(), print_trap_info(), print_vehicle_info(), print_visibility_info(), Character::sees_with_infrared(), Character::sees_with_specials(), sounds::sound_at(), u, map::veh_at(), veh_pointer_or_null(), VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, VIS_LIT, and tripoint::z.

Referenced by pre_print_all_tile_info().

◆ print_creature_info()

void game::print_creature_info ( const Creature creature,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 6209 of file game.cpp.

6211{
6212 int vLines = last_line - line;
6213 if( creature != nullptr && ( u.sees( *creature ) || creature == &u ) ) {
6214 line = creature->print_info( w_look, ++line, vLines, column );
6215 }
6216}

References creature, line(), Character::sees(), and u.

Referenced by print_all_tile_info().

◆ print_fields_info()

void game::print_fields_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line 
)
private

Definition at line 6172 of file game.cpp.

6174{
6175 const field &tmpfield = m.field_at( lp );
6176 for( auto &fld : tmpfield ) {
6177 const field_entry &cur = fld.second;
6178 if( fld.first.obj().has_fire && ( m.has_flag( TFLAG_FIRE_CONTAINER, lp ) ||
6179 m.ter( lp ) == t_pit_shallow || m.ter( lp ) == t_pit ) ) {
6180 const int max_width = getmaxx( w_look ) - column - 2;
6181 int lines = fold_and_print( w_look, point( column, ++line ), max_width, cur.color(),
6182 get_fire_fuel_string( lp ) ) - 1;
6183 line += lines;
6184 } else {
6185 mvwprintz( w_look, point( column, ++line ), cur.color(), cur.name() );
6186 }
6187 }
6188}
An active or passive effect existing on a tile.
Definition: field.h:20
nc_color color() const
Definition: field.cpp:94
std::string name() const
Definition: field.h:84
A variable sized collection of field entries on a given map square.
Definition: field.h:131
ter_id t_pit_shallow
Definition: mapdata.cpp:625
ter_id t_pit
Definition: mapdata.cpp:625

References field_entry::color(), map::field_at(), fold_and_print(), get_fire_fuel_string(), catacurses::getmaxx(), map::has_flag(), line(), m, mvwprintz(), field_entry::name(), t_pit, t_pit_shallow, map::ter(), and TFLAG_FIRE_CONTAINER.

Referenced by print_all_tile_info().

◆ print_graffiti_info()

void game::print_graffiti_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 6264 of file game.cpp.

6267{
6268 if( line > last_line ) {
6269 return;
6270 }
6271
6272 const int max_width = getmaxx( w_look ) - column - 2;
6273 if( m.has_graffiti_at( lp ) ) {
6274 fold_and_print( w_look, point( column, ++line ), max_width, c_light_gray,
6275 m.ter( lp ) == t_grave_new ? _( "Graffiti: %s" ) : _( "Inscription: %s" ),
6276 m.graffiti_at( lp ) );
6277 }
6278}
ter_id t_grave_new
Definition: mapdata.cpp:625

References _, c_light_gray, fold_and_print(), catacurses::getmaxx(), map::graffiti_at(), map::has_graffiti_at(), line(), m, t_grave_new, and map::ter().

Referenced by print_all_tile_info().

◆ print_items_info()

void game::print_items_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 6227 of file game.cpp.

6230{
6231 if( !m.sees_some_items( lp, u ) ) {
6232 return;
6233 } else if( m.has_flag( "CONTAINER", lp ) && !m.could_see_items( lp, u ) ) {
6234 mvwprintw( w_look, point( column, ++line ), _( "You cannot see what is inside of it." ) );
6235 } else if( u.has_effect( effect_blind ) || u.worn_with_flag( "BLIND" ) ) {
6236 mvwprintz( w_look, point( column, ++line ), c_yellow,
6237 _( "There's something there, but you can't see what it is." ) );
6238 return;
6239 } else {
6240 std::map<std::string, int> item_names;
6241 for( auto &item : m.i_at( lp ) ) {
6242 ++item_names[item.tname()];
6243 }
6244
6245 const int max_width = getmaxx( w_look ) - column - 1;
6246 for( auto it = item_names.begin(); it != item_names.end(); ++it ) {
6247 // last line but not last item
6248 if( line + 1 >= last_line && std::next( it ) != item_names.end() ) {
6249 mvwprintz( w_look, point( column, ++line ), c_yellow, _( "More items here…" ) );
6250 break;
6251 }
6252
6253 if( it->second > 1 ) {
6254 trim_and_print( w_look, point( column, ++line ), max_width, c_white,
6255 pgettext( "%s is the name of the item. %d is the quantity of that item.", "%s [%d]" ),
6256 it->first.c_str(), it->second );
6257 } else {
6258 trim_and_print( w_look, point( column, ++line ), max_width, c_white, it->first );
6259 }
6260 }
6261 }
6262}
bool could_see_items(const tripoint &p, const Creature &who) const
Check if the creature could see items at p if there were any items.
Definition: map.cpp:4759
static const efftype_id effect_blind("blind")

References _, c_white, c_yellow, map::could_see_items(), effect_blind, catacurses::getmaxx(), Creature::has_effect(), map::has_flag(), map::i_at(), line(), m, catacurses::mvwprintw(), mvwprintz(), pgettext(), map::sees_some_items(), item::tname(), trim_and_print(), u, and Character::worn_with_flag().

Referenced by print_all_tile_info().

◆ print_terrain_info()

void game::print_terrain_info ( const tripoint lp,
const catacurses::window w_look,
const std::string &  area_name,
int  column,
int &  line 
)
private

Definition at line 6099 of file game.cpp.

6102{
6103 const int max_width = getmaxx( w_look ) - column - 1;
6104 int lines;
6105
6106 const auto fmt_tile_info = []( const tripoint & lp ) {
6107 map &here = get_map();
6108 std::string ret;
6109 if( debug_mode ) {
6110 ret = string_format( "%s %s", lp.to_string(), here.ter( lp )->id );
6111 if( here.has_furn( lp ) ) {
6112 ret += "; " + here.furn( lp )->id.str();
6113 }
6114 } else {
6115 ret = here.tername( lp );
6116 if( here.has_furn( lp ) ) {
6117 ret += "; " + here.furnname( lp );
6118 }
6119 }
6120 return ret;
6121 };
6122
6123 std::string tile = string_format( "(%s) %s", area_name, fmt_tile_info( lp ) );
6124
6125 if( m.impassable( lp ) ) {
6126 lines = fold_and_print( w_look, point( column, line ), max_width, c_light_gray,
6127 _( "%s; Impassable" ),
6128 tile );
6129 } else {
6130 lines = fold_and_print( w_look, point( column, line ), max_width, c_light_gray,
6131 _( "%s; Movement cost %d" ),
6132 tile, m.move_cost( lp ) * 50 );
6133
6134 const auto ll = get_light_level( std::max( 1.0,
6135 LIGHT_AMBIENT_LIT - m.ambient_light_at( lp ) + 1.0 ) );
6136 mvwprintw( w_look, point( column, ++lines ), _( "Lighting: " ) );
6137 wprintz( w_look, ll.second, ll.first );
6138 }
6139
6140 std::string signage = m.get_signage( lp );
6141 if( !signage.empty() ) {
6142 trim_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
6143 // NOLINTNEXTLINE(cata-text-style): the question mark does not end a sentence
6144 u.has_trait( trait_ILLITERATE ) ? _( "Sign: ???" ) : _( "Sign: %s" ), signage );
6145 }
6146
6147 if( m.has_zlevels() && lp.z > -OVERMAP_DEPTH && !m.has_floor( lp ) ) {
6148 // Print info about stuff below
6149 tripoint below( lp.xy(), lp.z - 1 );
6150 std::string tile_below = fmt_tile_info( below );
6151
6152 if( !m.has_floor_or_support( lp ) ) {
6153 fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
6154 _( "Below: %s; No support" ),
6155 tile_below );
6156 } else {
6157 fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
6158 _( "Below: %s; Walkable" ),
6159 tile_below );
6160 }
6161 }
6162
6163 int map_features = fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
6164 m.features( lp ) );
6165 fold_and_print( w_look, point( column, ++lines ), max_width, c_light_gray, _( "Coverage: %d%%" ),
6166 m.coverage( lp ) );
6167 if( line < lines ) {
6168 line = lines + map_features - 1;
6169 }
6170}
Manage and cache data about a part of the map.
Definition: map.h:372
bool has_floor_or_support(const tripoint &p) const
Definition: map.cpp:2050
float ambient_light_at(const tripoint &p) const
Definition: lightmap.cpp:615
std::string features(const tripoint &p)
Definition: map.cpp:1725
int coverage(const tripoint &p) const
Returns coverage value of the tile.
Definition: map.cpp:6224
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:255
static constexpr float LIGHT_AMBIENT_LIT
Definition: lightmap.h:18
std::pair< std::string, nc_color > get_light_level(const float light)
Definition: output.cpp:1621
furn_str_id id
Definition: mapdata.h:490
ter_str_id id
Definition: mapdata.h:458

References _, map::ambient_light_at(), c_dark_gray, c_light_gray, map::coverage(), debug_mode, map::features(), fold_and_print(), map::furn(), map::furnname(), get_light_level(), get_map, map::get_signage(), catacurses::getmaxx(), map::has_floor(), map::has_floor_or_support(), map::has_furn(), Character::has_trait(), map::has_zlevels(), ter_t::id, furn_t::id, map::impassable(), LIGHT_AMBIENT_LIT, line(), m, map::move_cost(), catacurses::mvwprintw(), OVERMAP_DEPTH, cata::hash64_detail::ret, string_id< T >::str(), string_format(), map::ter(), map::tername(), tripoint::to_string(), trait_ILLITERATE, trim_and_print(), u, wprintz(), tripoint::xy(), and tripoint::z.

Referenced by print_all_tile_info().

◆ print_trap_info()

void game::print_trap_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line 
)
private

Definition at line 6190 of file game.cpp.

6192{
6193 const trap &tr = m.tr_at( lp );
6194 if( tr.can_see( lp, u ) ) {
6195 partial_con *pc = g->m.partial_con_at( lp );
6196 std::string tr_name;
6197 if( pc && tr.loadid == tr_unfinished_construction ) {
6198 const construction &built = pc->id.obj();
6199 tr_name = string_format( _( "Unfinished task: %s, %d%% complete" ), built.description,
6200 pc->counter / 100000 );
6201 } else {
6202 tr_name = tr.name();
6203 }
6204
6205 mvwprintz( w_look, point( column, ++line ), tr.color, tr_name );
6206 }
6207}
static const trap_str_id tr_unfinished_construction("tr_unfinished_construction")
std::string description
Definition: construction.h:51
construction_id id
Definition: construction.h:33
nc_color color
Definition: trap.h:93

References _, trap::can_see(), trap::color, partial_con::counter, construction::description, g, partial_con::id, line(), trap::loadid, m, mvwprintz(), trap::name(), int_id< T >::obj(), string_format(), map::tr_at(), tr_unfinished_construction, and u.

Referenced by print_all_tile_info().

◆ print_vehicle_info()

void game::print_vehicle_info ( const vehicle veh,
int  veh_part,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 6218 of file game.cpp.

6220{
6221 if( veh ) {
6222 mvwprintw( w_look, point( column, ++line ), _( "There is a %s there. Parts:" ), veh->name );
6223 line = veh->print_part_list( w_look, ++line, last_line, getmaxx( w_look ), veh_part );
6224 }
6225}
int print_part_list(const catacurses::window &win, int y1, int max_y, int width, int p, int hl=-1, bool detail=false) const
Prints a list of all parts to the screen inside of a boxed window, possibly highlighting a selected o...

References _, catacurses::getmaxx(), line(), catacurses::mvwprintw(), vehicle::name, and vehicle::print_part_list().

Referenced by print_all_tile_info().

◆ print_visibility_info()

void game::print_visibility_info ( const catacurses::window w_look,
int  column,
int &  line,
visibility_type  visibility 
)
private

Definition at line 6070 of file game.cpp.

6072{
6073 const char *visibility_message = nullptr;
6074 switch( visibility ) {
6075 case VIS_CLEAR:
6076 visibility_message = _( "Clearly visible." );
6077 break;
6078 case VIS_BOOMER:
6079 visibility_message = _( "A bright pink blur." );
6080 break;
6081 case VIS_BOOMER_DARK:
6082 visibility_message = _( "A pink blur." );
6083 break;
6084 case VIS_DARK:
6085 visibility_message = _( "Darkness." );
6086 break;
6087 case VIS_LIT:
6088 visibility_message = _( "Bright light." );
6089 break;
6090 case VIS_HIDDEN:
6091 visibility_message = _( "Unseen." );
6092 break;
6093 }
6094
6095 mvwprintw( w_look, point( line, column ), visibility_message );
6096 line += 2;
6097}

References _, line(), catacurses::mvwprintw(), VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, and VIS_LIT.

Referenced by print_all_tile_info().

◆ process_activity()

void game::process_activity ( )
private

Definition at line 1739 of file game.cpp.

1740{
1741 if( !u.activity ) {
1742 return;
1743 }
1744
1745 while( u.moves > 0 && u.activity ) {
1746 u.activity.do_turn( u );
1747 }
1748}
void do_turn(player &p)
Performs the activity for a single turn.

References Character::activity, player_activity::do_turn(), Creature::moves, and u.

Referenced by do_turn().

◆ process_artifact()

void game::process_artifact ( item it,
player p 
)

Definition at line 11844 of file game.cpp.

11845{
11846 const bool worn = p.is_worn( it );
11847 const bool wielded = ( &it == &p.weapon );
11848 std::vector<art_effect_passive> effects = it.type->artifact->effects_carried;
11849 if( worn ) {
11850 const std::vector<art_effect_passive> &ew = it.type->artifact->effects_worn;
11851 effects.insert( effects.end(), ew.begin(), ew.end() );
11852 }
11853 if( wielded ) {
11854 const std::vector<art_effect_passive> &ew = it.type->artifact->effects_wielded;
11855 effects.insert( effects.end(), ew.begin(), ew.end() );
11856 }
11857
11858 if( it.is_tool() ) {
11859 // Recharge it if necessary
11860 if( it.ammo_remaining() < it.ammo_capacity() && calendar::once_every( 1_minutes ) ) {
11861 //Before incrementing charge, check that any extra requirements are met
11862 if( check_art_charge_req( it ) ) {
11863 switch( it.type->artifact->charge_type ) {
11864 case ARTC_NULL:
11865 case NUM_ARTCS:
11866 break; // dummy entries
11867 case ARTC_TIME:
11868 // Once per hour
11869 if( calendar::once_every( 1_hours ) ) {
11870 it.charges++;
11871 }
11872 break;
11873 case ARTC_SOLAR:
11874 if( calendar::once_every( 10_minutes ) &&
11875 is_in_sunlight( p.pos() ) ) {
11876 it.charges++;
11877 }
11878 break;
11879 // Artifacts can inflict pain even on Deadened folks.
11880 // Some weird Lovecraftian thing. ;P
11881 // (So DON'T route them through mod_pain!)
11882 case ARTC_PAIN:
11883 if( calendar::once_every( 1_minutes ) ) {
11884 add_msg( m_bad, _( "You suddenly feel sharp pain for no reason." ) );
11885 p.mod_pain_noresist( 3 * rng( 1, 3 ) );
11886 it.charges++;
11887 }
11888 break;
11889 case ARTC_HP:
11890 if( calendar::once_every( 1_minutes ) ) {
11891 add_msg( m_bad, _( "You feel your body decaying." ) );
11892 p.hurtall( 1, nullptr );
11893 it.charges++;
11894 }
11895 break;
11896 case ARTC_FATIGUE:
11897 if( calendar::once_every( 1_minutes ) ) {
11898 add_msg( m_bad, _( "You feel fatigue seeping into your body." ) );
11899 u.mod_fatigue( 3 * rng( 1, 3 ) );
11900 u.mod_stamina( -90 * rng( 1, 3 ) * rng( 1, 3 ) * rng( 2, 3 ) );
11901 it.charges++;
11902 }
11903 break;
11904 // Portals are energetic enough to charge the item.
11905 // Tears in reality are consumed too, but can't charge it.
11906 case ARTC_PORTAL:
11907 for( const tripoint &dest : m.points_in_radius( p.pos(), 1 ) ) {
11908 m.remove_field( dest, fd_fatigue );
11909 if( m.tr_at( dest ).loadid == tr_portal ) {
11910 add_msg( m_good, _( "The portal collapses!" ) );
11911 m.remove_trap( dest );
11912 it.charges++;
11913 break;
11914 }
11915 }
11916 break;
11917 }
11918 }
11919 }
11920 }
11921
11922 for( const art_effect_passive &i : effects ) {
11923 switch( i ) {
11924 case AEP_STR_UP:
11925 p.mod_str_bonus( +4 );
11926 break;
11927 case AEP_DEX_UP:
11928 p.mod_dex_bonus( +4 );
11929 break;
11930 case AEP_PER_UP:
11931 p.mod_per_bonus( +4 );
11932 break;
11933 case AEP_INT_UP:
11934 p.mod_int_bonus( +4 );
11935 break;
11936 case AEP_ALL_UP:
11937 p.mod_str_bonus( +2 );
11938 p.mod_dex_bonus( +2 );
11939 p.mod_per_bonus( +2 );
11940 p.mod_int_bonus( +2 );
11941 break;
11942 case AEP_SPEED_UP:
11943 // Handled in player::current_speed()
11944 break;
11945
11946 case AEP_PBLUE:
11947 if( p.get_rad() > 0 ) {
11948 p.mod_rad( -1 );
11949 }
11950 break;
11951
11952 case AEP_SMOKE:
11953 if( one_in( 10 ) ) {
11954 tripoint pt( p.posx() + rng( -1, 1 ),
11955 p.posy() + rng( -1, 1 ),
11956 p.posz() );
11957 m.add_field( pt, fd_smoke, rng( 1, 3 ) );
11958 }
11959 break;
11960
11961 case AEP_SNAKES:
11962 break; // Handled in player::hit()
11963
11964 case AEP_EXTINGUISH:
11965 for( const tripoint &dest : m.points_in_radius( p.pos(), 1 ) ) {
11966 m.mod_field_age( dest, fd_fire, -1_turns );
11967 }
11968 break;
11969
11970 case AEP_FUN:
11971 //Bonus fluctuates, wavering between 0 and 30-ish - usually around 12
11972 p.add_morale( MORALE_FEELING_GOOD, rng( 1, 2 ) * rng( 2, 3 ), 0, 3_turns, 0_turns, false );
11973 break;
11974
11975 case AEP_HUNGER:
11976 if( one_in( 100 ) ) {
11977 p.mod_stored_kcal( -10 );
11978 }
11979 break;
11980
11981 case AEP_THIRST:
11982 if( one_in( 120 ) ) {
11983 p.mod_thirst( 1 );
11984 }
11985 break;
11986
11987 case AEP_EVIL:
11988 if( one_in( 150 ) ) { // Once every 15 minutes, on average
11989 p.add_effect( effect_evil, 30_minutes );
11990 if( it.is_armor() ) {
11991 if( !worn ) {
11992 add_msg( _( "You have an urge to wear the %s." ),
11993 it.tname() );
11994 }
11995 } else if( !wielded ) {
11996 add_msg( _( "You have an urge to wield the %s." ),
11997 it.tname() );
11998 }
11999 }
12000 break;
12001
12002 case AEP_SCHIZO:
12003 break; // Handled in player::suffer()
12004
12005 case AEP_RADIOACTIVE:
12006 if( one_in( 4 ) ) {
12007 p.irradiate( 1.0f );
12008 }
12009 break;
12010
12011 case AEP_STR_DOWN:
12012 p.mod_str_bonus( -3 );
12013 break;
12014
12015 case AEP_DEX_DOWN:
12016 p.mod_dex_bonus( -3 );
12017 break;
12018
12019 case AEP_PER_DOWN:
12020 p.mod_per_bonus( -3 );
12021 break;
12022
12023 case AEP_INT_DOWN:
12024 p.mod_int_bonus( -3 );
12025 break;
12026
12027 case AEP_ALL_DOWN:
12028 p.mod_str_bonus( -2 );
12029 p.mod_dex_bonus( -2 );
12030 p.mod_per_bonus( -2 );
12031 p.mod_int_bonus( -2 );
12032 break;
12033
12034 case AEP_SPEED_DOWN:
12035 break; // Handled in player::current_speed()
12036
12037 default:
12038 //Suppress warnings
12039 break;
12040 }
12041 }
12042 // Recalculate, as it might have changed (by mod_*_bonus above)
12043 p.str_cur = p.get_str();
12044 p.int_cur = p.get_int();
12045 p.dex_cur = p.get_dex();
12046 p.per_cur = p.get_per();
12047}
@ ARTC_PORTAL
Definition: artifact.h:69
@ ARTC_FATIGUE
Definition: artifact.h:68
@ ARTC_NULL
Definition: artifact.h:63
@ ARTC_SOLAR
Definition: artifact.h:65
@ NUM_ARTCS
Definition: artifact.h:70
@ ARTC_HP
Definition: artifact.h:67
@ ARTC_TIME
Definition: artifact.h:64
@ ARTC_PAIN
Definition: artifact.h:66
virtual void mod_per_bonus(int nper)
Definition: character.cpp:4058
virtual void mod_dex_bonus(int ndex)
Definition: character.cpp:4053
int str_cur
Definition: character.h:304
void mod_rad(int mod)
Definition: character.cpp:7057
virtual int get_dex() const
Definition: character.cpp:3942
virtual void mod_stored_kcal(int nkcal)
Modifiers for need values exclusive to characters.
Definition: character.cpp:4173
bool is_worn(const item &thing) const
Definition: character.h:1142
virtual int get_int() const
Definition: character.cpp:3950
virtual void mod_fatigue(int nfatigue)
Definition: character.cpp:4304
virtual void mod_str_bonus(int nstr)
Definition: character.cpp:4048
int int_cur
Definition: character.h:306
int get_rad() const
Definition: character.cpp:7047
void add_morale(const morale_type &type, int bonus, int max_bonus=0, const time_duration &duration=1_hours, const time_duration &decay_start=30_minutes, bool capped=false, const itype *item_type=nullptr)
Definition: character.cpp:8923
virtual int get_per() const
Definition: character.cpp:3946
void mod_stamina(int mod)
Definition: character.cpp:7084
void hurtall(int dam, Creature *source, bool disturb=true)
Hurts all body parts for dam, no armor reduction.
Definition: character.cpp:8491
bool irradiate(float rads, bool bypass=false)
Handles mitigation and application of radiation.
Definition: suffer.cpp:1532
virtual void mod_int_bonus(int nint)
Definition: character.cpp:4063
virtual void mod_pain_noresist(int npain)
Definition: creature.cpp:1346
bool is_in_sunlight(const tripoint &p)
Returns true if p is outdoors and it is sunny.
Definition: game.cpp:5143
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7145
bool is_tool() const
Definition: item.cpp:6722
int ammo_capacity() const
Maximum quantity of ammunition loadable for tool, gun or auxiliary gunmod.
Definition: item.cpp:7172
int charges
Definition: item.h:2192
bool is_armor() const
Definition: item.cpp:6477
const itype * type
Definition: item.h:2153
bool add_field(const tripoint &p, const field_type_id &type_id, int intensity=INT_MAX, const time_duration &age=0_turns, bool hit_player=true)
Add field entry at point, or set intensity if present.
Definition: map.cpp:5400
time_duration mod_field_age(const tripoint &p, const field_type_id &type, const time_duration &offset)
Increment/decrement age of field entry at point.
Definition: map.cpp:5320
void remove_trap(const tripoint &p)
Definition: map.cpp:5265
art_effect_passive
Definition: enums.h:99
@ AEP_EXTINGUISH
Definition: enums.h:114
field_type_id fd_smoke
Definition: field_type.cpp:346
field_type_id fd_fatigue
Definition: field_type.cpp:354
static const efftype_id effect_evil("evil")
static const trap_str_id tr_portal("tr_portal")
const morale_type MORALE_FEELING_GOOD("morale_feeling_good")
cata::value_ptr< islot_artifact > artifact
Definition: itype.h:865

References _, Creature::add_effect(), map::add_field(), Character::add_morale(), add_msg(), AEP_ALL_DOWN, AEP_ALL_UP, AEP_DEX_DOWN, AEP_DEX_UP, AEP_EVIL, AEP_EXTINGUISH, AEP_FUN, AEP_HUNGER, AEP_INT_DOWN, AEP_INT_UP, AEP_PBLUE, AEP_PER_DOWN, AEP_PER_UP, AEP_RADIOACTIVE, AEP_SCHIZO, AEP_SMOKE, AEP_SNAKES, AEP_SPEED_DOWN, AEP_SPEED_UP, AEP_STR_DOWN, AEP_STR_UP, AEP_THIRST, item::ammo_capacity(), item::ammo_remaining(), ARTC_FATIGUE, ARTC_HP, ARTC_NULL, ARTC_PAIN, ARTC_PORTAL, ARTC_SOLAR, ARTC_TIME, itype::artifact, item::charges, check_art_charge_req(), Character::dex_cur, effect_evil, fd_fatigue, fd_fire, fd_smoke, Character::get_dex(), Character::get_int(), Character::get_per(), Character::get_rad(), Character::get_str(), Character::hurtall(), Character::int_cur, Character::irradiate(), item::is_armor(), is_in_sunlight(), item::is_tool(), Character::is_worn(), trap::loadid, m, m_bad, m_good, Character::mod_dex_bonus(), Character::mod_fatigue(), map::mod_field_age(), Character::mod_int_bonus(), Creature::mod_pain_noresist(), Character::mod_per_bonus(), Character::mod_rad(), Character::mod_stamina(), Character::mod_stored_kcal(), Character::mod_str_bonus(), Character::mod_thirst(), MORALE_FEELING_GOOD, NUM_ARTCS, calendar::once_every(), one_in(), Character::per_cur, map::points_in_radius(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), map::remove_field(), map::remove_trap(), rng(), Character::str_cur, item::tname(), map::tr_at(), tr_portal, item::type, u, and Character::weapon.

◆ process_voluntary_act_interrupt()

void game::process_voluntary_act_interrupt ( )
private

Definition at line 1700 of file game.cpp.

1701{
1702 if( u.has_effect( effect_sleep ) ) {
1703 // Can't interrupt
1704 return;
1705 }
1706
1707 bool has_activity = u.activity && u.activity.moves_left > 0;
1708 bool is_travelling = u.has_destination() && !u.omt_path.empty();
1709
1710 if( !has_activity && !is_travelling ) {
1711 // Nohing to interrupt
1712 return;
1713 }
1714
1715 // Key poll may be quite expensive, so limit it to 10 times per second.
1716 static auto last_poll = std::chrono::steady_clock::now();
1717 auto now = std::chrono::steady_clock::now();
1718 int64_t difference = std::chrono::duration_cast<std::chrono::milliseconds>
1719 ( now - last_poll ).count();
1720
1721 if( difference > 100 ) {
1723 last_poll = now;
1724 }
1725
1726 // If player is performing a task and a monster is dangerously close, warn them
1727 // regardless of previous safemode warnings
1728 if( has_activity && !u.has_activity( activity_id( "ACT_AIM" ) ) &&
1730 Creature *hostile_critter = is_hostile_very_close();
1731 if( hostile_critter != nullptr ) {
1733 string_format( _( "The %s is dangerously close!" ),
1734 hostile_critter->get_name() ) );
1735 }
1736 }
1737}
bool has_activity(const activity_id &type) const
Check if player currently has a given activity.
Definition: character.cpp:9054
virtual std::string get_name() const =0
void handle_key_blocking_activity()
Definition: game.cpp:2053
int moves_left
The number of moves remaining in this activity before it is complete.

References _, Character::activity, cancel_activity_or_ignore_query(), effect_sleep, Creature::get_name(), handle_key_blocking_activity(), Character::has_activity(), Character::has_destination(), Creature::has_effect(), hostile_spotted_near, player_activity::is_distraction_ignored(), is_hostile_very_close(), player_activity::moves_left, Character::omt_path, string_format(), and u.

Referenced by do_turn().

◆ prompt_dangerous_tile()

bool game::prompt_dangerous_tile ( const tripoint dest_loc) const

Definition at line 9246 of file game.cpp.

9247{
9248 std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );
9249
9250 if( !harmful_stuff.empty() &&
9251 !query_yn( _( "Really step into %s?" ), enumerate_as_string( harmful_stuff ) ) ) {
9252 return false;
9253 }
9254 if( !harmful_stuff.empty() && u.is_mounted() &&
9255 m.tr_at( dest_loc ).loadid == tr_ledge ) {
9256 add_msg( m_warning, _( "Your %s refuses to move over that ledge!" ),
9257 u.mounted_creature->get_name() );
9258 return false;
9259 }
9260 return true;
9261}

References _, add_msg(), enumerate_as_string(), get_dangerous_tile(), Character::is_mounted(), trap::loadid, m, m_warning, Character::mounted_creature, query_yn(), map::tr_at(), tr_ledge, and u.

Referenced by npc_menu(), and walk_move().

◆ quickload()

void game::quickload ( )
private

Definition at line 11812 of file game.cpp.

11813{
11814 const WORLDPTR active_world = world_generator->active_world;
11815 if( active_world == nullptr ) {
11816 return;
11817 }
11818
11819 if( active_world->save_exists( save_t::from_player_name( u.name ) ) ) {
11820 if( moves_since_last_save != 0 ) { // See if we need to reload anything
11821 MAPBUFFER.reset();
11823 try {
11824 setup();
11825 } catch( const std::exception &err ) {
11826 debugmsg( "Error: %s", err.what() );
11827 }
11829 }
11830 } else {
11831 popup_getkey( _( "No saves for %s yet." ), u.name );
11832 }
11833}
bool load(const std::string &world)
Attempt to load first valid save (if any) in world.
Definition: game.cpp:2817
void setup()
Definition: game.cpp:557
static save_t from_player_name(const std::string &name)
int popup_getkey(const char *const mes, Args &&... args)
Definition: output.h:500
bool save_exists(const save_t &name) const

References _, overmapbuffer::clear(), debugmsg, save_t::from_player_name(), load(), MAPBUFFER, moves_since_last_save, Character::name, overmap_buffer, popup_getkey(), mapbuffer::reset(), WORLD::save_exists(), setup(), u, and world_generator.

Referenced by handle_action().

◆ quicksave()

void game::quicksave ( )

Definition at line 11790 of file game.cpp.

11791{
11792 //Don't autosave if the player hasn't done anything since the last autosave/quicksave,
11793 if( !moves_since_last_save ) {
11794 return;
11795 }
11796 add_msg( m_info, _( "Saving game, this may take a while" ) );
11797
11799 popup.message( "%s", _( "Saving game, this may take a while" ) );
11802
11803 time_t now = time( nullptr ); //timestamp for start of saving procedure
11804
11805 //perform save
11806 save();
11807 //Now reset counters for autosaving, so we don't immediately autosave after a quicksave or autosave.
11809 last_save_timestamp = now;
11810}

References _, add_msg(), last_save_timestamp, m_info, moves_since_last_save, popup(), ui_manager::redraw(), refresh_display(), and save().

Referenced by autosave(), and handle_action().

◆ reenter_fullscreen()

void game::reenter_fullscreen ( )

Definition at line 545 of file game.cpp.

546{
547 if( was_fullscreen ) {
548 if( !fullscreen ) {
550 }
551 }
552}

References fullscreen, toggle_fullscreen(), and was_fullscreen.

Referenced by list_items_monsters(), and look_around().

◆ reload()

void game::reload ( item_location loc,
bool  prompt = false,
bool  empty = true 
)

Definition at line 8829 of file game.cpp.

8830{
8832 item *it = loc.get_item();
8833
8834 // bows etc. do not need to reload. select favorite ammo for them instead
8835 if( it->has_flag( "RELOAD_AND_SHOOT" ) ) {
8837 if( !opt ) {
8838 return;
8839 } else if( u.ammo_location && opt.ammo == u.ammo_location ) {
8841 } else {
8842 u.ammo_location = opt.ammo;
8843 }
8844 return;
8845 }
8846
8847 switch( u.rate_action_reload( *it ) ) {
8848 case hint_rating::iffy:
8849 if( ( it->is_ammo_container() || it->is_magazine() ) && it->ammo_remaining() > 0 &&
8850 it->ammo_remaining() == it->ammo_capacity() ) {
8851 add_msg( m_info, _( "The %s is already fully loaded!" ), it->tname() );
8852 return;
8853 }
8854 if( it->is_ammo_belt() ) {
8855 const auto &linkage = it->type->magazine->linkage;
8856 if( linkage && !u.has_charges( *linkage, 1 ) ) {
8857 add_msg( m_info, _( "You need at least one %s to reload the %s!" ),
8858 item::nname( *linkage, 1 ), it->tname() );
8859 return;
8860 }
8861 }
8862 if( it->is_watertight_container() && it->is_container_full() ) {
8863 add_msg( m_info, _( "The %s is already full!" ), it->tname() );
8864 return;
8865 }
8866
8867 // intentional fall-through
8868
8869 case hint_rating::cant:
8870 add_msg( m_info, _( "You can't reload a %s!" ), it->tname() );
8871 return;
8872
8873 case hint_rating::good:
8874 break;
8875 }
8876
8877 bool use_loc = true;
8878 if( !it->has_flag( "ALLOWS_REMOTE_USE" ) ) {
8879 it = loc.obtain( u ).get_item();
8880 use_loc = false;
8881 }
8882
8883 // for holsters and ammo pouches try to reload any contained item
8884 if( it->type->can_use( "holster" ) && !it->contents.empty() ) {
8885 it = &it->contents.front();
8886 }
8887
8888 // for bandoliers we currently defer to iuse_actor methods
8889 if( it->is_bandolier() ) {
8890 auto ptr = dynamic_cast<const bandolier_actor *>
8891 ( it->type->get_use( "bandolier" )->get_actor_ptr() );
8892 ptr->reload( u, *it );
8893 return;
8894 }
8895
8897
8898 if( opt.ammo.get_item() == nullptr ) {
8899 return;
8900 }
8901
8902 if( opt ) {
8903 int moves = opt.moves();
8904 if( it->get_var( "dirt", 0 ) > 7800 ) {
8905 add_msg( m_warning, _( "You struggle to reload the fouled %s." ), it->tname() );
8906 moves += 2500;
8907 }
8908
8909 u.assign_activity( activity_id( "ACT_RELOAD" ), moves, opt.qty() );
8910 if( use_loc ) {
8911 u.activity.targets.emplace_back( loc );
8912 } else {
8913 u.activity.targets.emplace_back( u, const_cast<item *>( opt.target ) );
8914 }
8915 u.activity.targets.push_back( std::move( opt.ammo ) );
8916 }
8917}
bool has_charges(const itype_id &it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >) const
Definition: character.cpp:9427
Store ammo and later reload using it.
Definition: iuse_actor.h:846
int moves() const
Definition: item.cpp:7786
const item * target
Definition: item.h:482
int qty() const
Definition: item.h:485
item & front()
this is an artifact of the previous code using front() everywhere for contents.
bool empty() const
item * get_item()
Gets the selected item or nullptr.
item_location obtain(Character &ch, int qty=-1)
Move an item from the location to the character inventory.
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1016
bool is_ammo_container() const
Definition: item.cpp:6435
bool is_watertight_container() const
Whether this is a container which can be used to store liquids.
Definition: item.cpp:6497
static std::string nname(const itype_id &id, unsigned int quantity=1)
Returns the translated item name for the item with given id.
Definition: item.cpp:9589
bool is_ammo_belt() const
Definition: item.cpp:6340
item_contents contents
Definition: item.h:2154
bool is_container_full(bool allow_bucket=false) const
Whether this item has no more free capacity for its current content.
Definition: item.cpp:6615
bool is_bandolier() const
Definition: item.cpp:6345
bool is_magazine() const
Definition: item.cpp:6330
const void * ptr(const T *p)
\rst Converts p to const void* for pointer formatting.
static item::reload_option favorite_ammo_or_select(const player &u, const item &it, bool empty, bool prompt)
Definition: game.cpp:8810
@ prompt
Definition: pickup.h:30
const use_function * get_use(const std::string &iuse_name) const
Definition: itype.cpp:91
cata::value_ptr< islot_magazine > magazine
Definition: itype.h:860
bool can_use(const std::string &iuse_name) const
Definition: itype.cpp:86

References _, Character::activity, add_msg(), item::reload_option::ammo, item::ammo_capacity(), player::ammo_location, item::ammo_remaining(), Character::assign_activity(), itype::can_use(), cant, item::contents, item_contents::empty(), favorite_ammo_or_select(), item_contents::front(), use_function::get_actor_ptr(), item_location::get_item(), itype::get_use(), item::get_var(), good, Character::has_charges(), item::has_flag(), iffy, item::is_ammo_belt(), item::is_ammo_container(), item::is_bandolier(), item::is_container_full(), item::is_magazine(), item::is_watertight_container(), m_info, m_warning, itype::magazine, item_location::make_dirty(), avatar_action::move(), item::reload_option::moves(), item::nname(), item_location::obtain(), pickup::prompt, ptr(), item::reload_option::qty(), player::rate_action_reload(), player::select_ammo(), item::reload_option::target, player_activity::targets, item::tname(), item::type, and u.

Referenced by inventory_item_menu(), reload_item(), and reload_wielded().

◆ reload_item()

void game::reload_item ( )

Definition at line 8920 of file game.cpp.

8921{
8922 item_location item_loc = inv_map_splice( [&]( const item & it ) {
8923 return u.rate_action_reload( it ) == hint_rating::good;
8924 }, _( "Reload item" ), 1, _( "You have nothing to reload." ) );
8925
8926 if( !item_loc ) {
8927 add_msg( _( "Never mind." ) );
8928 return;
8929 }
8930
8931 reload( item_loc );
8932}
item_location inv_map_splice(item_filter filter, const std::string &title, int radius=0, const std::string &none_message="")
Custom-filtered menu for inventory and nearby items and those that within specified radius.

References _, add_msg(), good, inv_map_splice(), player::rate_action_reload(), reload(), and u.

Referenced by handle_action().

◆ reload_npcs()

void game::reload_npcs ( )

Unloads, then loads the NPCs.

Definition at line 957 of file game.cpp.

958{
959 // TODO: Make it not invoke the "on_unload" command for the NPCs that will be loaded anyway
960 // and not invoke "on_load" for those NPCs that avoided unloading this way.
961 unload_npcs();
962 load_npcs();
963}

References load_npcs(), and unload_npcs().

Referenced by load(), overmap_npc_move(), vertical_move(), and vertical_shift().

◆ reload_tileset()

void game::reload_tileset ( )

Definition at line 518 of file game.cpp.

519{
520#if defined(TILES)
521 try {
522 tilecontext->reinit();
523 tilecontext->load_tileset( get_option<std::string>( "TILES" ), false, true );
524 tilecontext->do_tile_loading_report();
525 } catch( const std::exception &err ) {
526 popup( _( "Loading the tileset failed: %s" ), err.what() );
527 }
528 g->reset_zoom();
529 g->mark_main_ui_adaptor_resize();
530#endif // TILES
531}

References _, g, and popup().

Referenced by handle_action().

◆ reload_weapon()

void game::reload_weapon ( bool  try_everything = true)

Definition at line 8944 of file game.cpp.

8945{
8946 // As a special streamlined activity, hitting reload repeatedly should:
8947 // Reload wielded gun
8948 // First reload a magazine if necessary.
8949 // Then load said magazine into gun.
8950 // Reload magazines that are compatible with the current gun.
8951 // Reload other guns in inventory.
8952 // Reload misc magazines in inventory.
8953 std::vector<item_location> reloadables = u.find_reloadables();
8954 std::sort( reloadables.begin(), reloadables.end(),
8955 [this]( const item_location & a, const item_location & b ) {
8956 const item *ap = a.get_item();
8957 const item *bp = b.get_item();
8958 // Current wielded weapon comes first.
8959 if( this->u.is_wielding( *bp ) ) {
8960 return false;
8961 }
8962 if( this->u.is_wielding( *ap ) ) {
8963 return true;
8964 }
8965 // Second sort by affiliation with wielded gun
8966 const std::set<itype_id> compatible_magazines = this->u.weapon.magazine_compatible();
8967 const bool mag_ap = compatible_magazines.count( ap->typeId() ) > 0;
8968 const bool mag_bp = compatible_magazines.count( bp->typeId() ) > 0;
8969 if( mag_ap != mag_bp ) {
8970 return mag_ap;
8971 }
8972 // Third sort by gun vs magazine,
8973 if( ap->is_gun() != bp->is_gun() ) {
8974 return ap->is_gun();
8975 }
8976 // Finally sort by speed to reload.
8977 return ( ap->get_reload_time() * ( ap->ammo_capacity() - ap->ammo_remaining() ) ) <
8978 ( bp->get_reload_time() * ( bp->ammo_capacity() - bp->ammo_remaining() ) );
8979 } );
8980 for( item_location &candidate : reloadables ) {
8981 std::vector<item::reload_option> ammo_list;
8982 u.list_ammo( *candidate.get_item(), ammo_list, false );
8983 if( !ammo_list.empty() ) {
8984 reload( candidate, false, false );
8985 return;
8986 }
8987 }
8988 // Just for testing, bail out here to avoid unwanted side effects.
8989 if( !try_everything ) {
8990 return;
8991 }
8992 // If we make it here and haven't found anything to reload, start looking elsewhere.
8993 vehicle *veh = veh_pointer_or_null( m.veh_at( u.pos() ) );
8994 turret_data turret;
8995 if( veh && ( turret = veh->turret_query( u.pos() ) ) && turret.can_reload() ) {
8996 item::reload_option opt = g->u.select_ammo( *turret.base(), true );
8997 if( opt ) {
8998 g->u.assign_activity( activity_id( "ACT_RELOAD" ), opt.moves(), opt.qty() );
8999 g->u.activity.targets.emplace_back( turret.base() );
9000 g->u.activity.targets.push_back( std::move( opt.ammo ) );
9001 }
9002 return;
9003 }
9004
9005 reload_item();
9006}
std::vector< item_location > find_reloadables()
Searches for weapons and magazines that can be reloaded.
Definition: character.cpp:2670
bool list_ammo(const item &base, std::vector< item::reload_option > &ammo_list, bool empty=true) const
Definition: player.cpp:2435
bool can_reload() const
Definition: turret.cpp:212
item_location base()
Get base item location.
Definition: turret.cpp:84
turret_data turret_query(vehicle_part &pt)
Get firing data for a turret.
Definition: turret.cpp:55
constexpr double a
Definition: magic.cpp:1029
constexpr double b
Definition: magic.cpp:1030

References a, b, Character::find_reloadables(), and u.

Referenced by handle_action().

◆ reload_wielded()

void game::reload_wielded ( bool  prompt = false)

Definition at line 8934 of file game.cpp.

8935{
8936 if( u.weapon.is_null() || !u.weapon.is_reloadable() ) {
8937 add_msg( _( "You aren't holding something you can reload." ) );
8938 return;
8939 }
8940 item_location item_loc = item_location( u, &u.weapon );
8941 reload( item_loc, prompt );
8942}
bool is_null() const
Definition: item.cpp:724
bool is_reloadable() const
Is it ever possible to reload this item? Only the base item is considered with any mods ignored.
Definition: item.cpp:9497

References _, add_msg(), item::is_null(), item::is_reloadable(), pickup::prompt, reload(), u, and Character::weapon.

Referenced by handle_action().

◆ remoteveh()

vehicle * game::remoteveh ( )

Returns the current remotely controlled vehicle.

Definition at line 2558 of file game.cpp.

2559{
2561 return remoteveh_cache;
2562 }
2564 std::stringstream remote_veh_string( u.get_value( "remote_controlling_vehicle" ) );
2565 if( remote_veh_string.str().empty() ||
2567 remoteveh_cache = nullptr;
2568 } else {
2569 tripoint vp;
2570 remote_veh_string >> vp.x >> vp.y >> vp.z;
2571 vehicle *veh = veh_pointer_or_null( m.veh_at( vp ) );
2572 if( veh && veh->fuel_left( itype_battery, true ) > 0 ) {
2573 remoteveh_cache = veh;
2574 } else {
2575 remoteveh_cache = nullptr;
2576 }
2577 }
2578 return remoteveh_cache;
2579}
vehicle * remoteveh_cache
Definition: game.h:1093
int fuel_left(const itype_id &ftype, bool recurse=false) const
Definition: vehicle.cpp:3179
static const bionic_id bio_remote("bio_remote")
static const itype_id itype_remotevehcontrol("remotevehcontrol")
static const itype_id itype_battery("battery")

References bio_remote, vehicle::fuel_left(), Creature::get_value(), Character::has_active_bionic(), Character::has_active_item(), itype_battery, itype_remotevehcontrol, m, remoteveh_cache, remoteveh_cache_time, calendar::turn, u, map::veh_at(), veh_pointer_or_null(), tripoint::x, tripoint::y, and tripoint::z.

Referenced by control_vehicle(), and handle_action().

◆ remove_npc_follower()

void game::remove_npc_follower ( const character_id id)

Remove follower id from follower set.

Definition at line 1962 of file game.cpp.

1963{
1964 follower_ids.erase( id );
1965 u.follower_ids.erase( id );
1966}

References follower_ids, player::follower_ids, and u.

Referenced by cleanup_dead().

◆ remove_zombie()

void game::remove_zombie ( const monster critter)

Definition at line 5022 of file game.cpp.

5023{
5024 critter_tracker->remove( critter );
5025}

References critter_tracker.

Referenced by despawn_monster(), disable_robot(), start_game(), and vertical_move().

◆ replace_stair_monsters()

void game::replace_stair_monsters ( )
private

Definition at line 11310 of file game.cpp.

11311{
11312 for( auto &elem : coming_to_stairs ) {
11313 elem.staircount = 0;
11314 const tripoint pnt( elem.pos().xy(), get_levz() );
11315 place_critter_around( make_shared_fast<monster>( elem ), pnt, 10 );
11316 }
11317
11318 coming_to_stairs.clear();
11319}
std::vector< monster > coming_to_stairs
Definition: game.h:1031

References coming_to_stairs, get_levz(), and place_critter_around().

◆ reset_item_list_state()

void game::reset_item_list_state ( const catacurses::window window,
int  height,
bool  bRadiusSort 
)
private

Definition at line 7411 of file game.cpp.

7412{
7413 const int width = getmaxx( window );
7414 for( int i = 1; i < TERMX; i++ ) {
7415 if( i < width ) {
7416 mvwputch( window, point( i, 0 ), c_light_gray, LINE_OXOX ); // -
7417 mvwputch( window, point( i, TERMY - height - 1 ), c_light_gray,
7418 LINE_OXOX ); // -
7419 }
7420
7421 if( i < TERMY - height ) {
7422 mvwputch( window, point( 0, i ), c_light_gray, LINE_XOXO ); // |
7423 mvwputch( window, point( width - 1, i ), c_light_gray, LINE_XOXO ); // |
7424 }
7425 }
7426
7427 mvwputch( window, point_zero, c_light_gray, LINE_OXXO ); // |^
7428 mvwputch( window, point( width - 1, 0 ), c_light_gray, LINE_OOXX ); // ^|
7429
7430 mvwputch( window, point( 0, TERMY - height - 1 ), c_light_gray,
7431 LINE_XXXO ); // |-
7432 mvwputch( window, point( width - 1, TERMY - height - 1 ), c_light_gray,
7433 LINE_XOXX ); // -|
7434
7435 mvwprintz( window, point( 2, 0 ), c_light_green, "<Tab> " );
7436 wprintz( window, c_white, _( "Items" ) );
7437
7438 std::string sSort;
7439 if( bRadiusSort ) {
7440 //~ Sort type: distance.
7441 sSort = _( "<s>ort: dist" );
7442 } else {
7443 //~ Sort type: category.
7444 sSort = _( "<s>ort: cat" );
7445 }
7446
7447 int letters = utf8_width( sSort );
7448
7449 shortcut_print( window, point( getmaxx( window ) - letters, 0 ), c_white, c_light_green, sSort );
7450
7451 std::vector<std::string> tokens;
7452 if( !sFilter.empty() ) {
7453 tokens.emplace_back( _( "<R>eset" ) );
7454 }
7455
7456 tokens.emplace_back( _( "<E>xamine" ) );
7457 tokens.emplace_back( _( "<C>ompare" ) );
7458 tokens.emplace_back( _( "<F>ilter" ) );
7459 tokens.emplace_back( _( "<+/->Priority" ) );
7460
7461 int gaps = tokens.size() + 1;
7462 letters = 0;
7463 int n = tokens.size();
7464 for( int i = 0; i < n; i++ ) {
7465 letters += utf8_width( tokens[i] ) - 2; //length ignores < >
7466 }
7467
7468 int usedwidth = letters;
7469 const int gap_spaces = ( width - usedwidth ) / gaps;
7470 usedwidth += gap_spaces * gaps;
7471 point pos( gap_spaces + ( width - usedwidth ) / 2, TERMY - height - 1 );
7472
7473 for( int i = 0; i < n; i++ ) {
7474 pos.x += shortcut_print( window, pos, c_white, c_light_green,
7475 tokens[i] ) + gap_spaces;
7476 }
7477}
#define LINE_OOXX
Definition: output.h:43
#define LINE_OXXO
Definition: output.h:42

References _, c_light_gray, c_light_green, c_white, catacurses::getmaxx(), LINE_OOXX, LINE_OXOX, LINE_OXXO, LINE_XOXO, LINE_XOXX, LINE_XXXO, mvwprintz(), mvwputch(), point_zero, sFilter, shortcut_print(), TERMX, TERMY, utf8_width(), wprintz(), and point::x.

Referenced by list_items().

◆ reset_light_level()

void game::reset_light_level ( )

Definition at line 3919 of file game.cpp.

3920{
3921 for( float &lev : latest_lightlevels ) {
3922 lev = -std::numeric_limits<float>::max();
3923 }
3924}

References latest_lightlevels.

Referenced by do_turn(), and game().

◆ reset_npc_dispositions()

void game::reset_npc_dispositions ( )
private

Definition at line 2994 of file game.cpp.

2995{
2996 for( auto elem : follower_ids ) {
2997 shared_ptr_fast<npc> npc_to_get = overmap_buffer.find_npc( elem );
2998 if( !npc_to_get ) {
2999 continue;
3000 }
3001 npc *npc_to_add = npc_to_get.get();
3002 npc_to_add->chatbin.missions.clear();
3003 npc_to_add->chatbin.missions_assigned.clear();
3004 npc_to_add->mission = NPC_MISSION_NULL;
3005 npc_to_add->chatbin.mission_selected = nullptr;
3006 npc_to_add->set_attitude( NPCATT_NULL );
3007 npc_to_add->op_of_u.anger = 0;
3008 npc_to_add->op_of_u.fear = 0;
3009 npc_to_add->op_of_u.trust = 0;
3010 npc_to_add->op_of_u.value = 0;
3011 npc_to_add->op_of_u.owed = 0;
3012 npc_to_add->set_fac( faction_id( "no_faction" ) );
3014 npc_to_add->global_omt_location(),
3015 npc_to_add->getID() ) );
3016
3017 }
3018
3019}
void set_attitude(npc_attitude new_attitude)
Definition: npc.cpp:3141
npc_chatbin chatbin
Definition: npc.h:1329
void add_new_mission(mission *miss)
See npc_chatbin::add_new_mission.
Definition: npc.cpp:2637
npc_opinion op_of_u
Definition: npc.h:1328
void set_fac(const faction_id &id)
Definition: npc.cpp:465
std::vector< mission * > missions_assigned
Mission that have been assigned by this NPC to a player character.
Definition: npc.h:752
mission * mission_selected
The mission (if any) that we talk about right now.
Definition: npc.h:757
std::vector< mission * > missions
Missions that the NPC can give out.
Definition: npc.h:748
int value
Definition: npc.h:242
int trust
Definition: npc.h:240
int owed
Definition: npc.h:244
int fear
Definition: npc.h:241
int anger
Definition: npc.h:243

References npc::add_new_mission(), npc_opinion::anger, npc::chatbin, npc_opinion::fear, overmapbuffer::find_npc(), follower_ids, Character::getID(), Character::global_omt_location(), npc::mission, npc_chatbin::mission_selected, npc_chatbin::missions, npc_chatbin::missions_assigned, NPC_MISSION_NULL, NPCATT_NULL, npc::op_of_u, ORIGIN_ANY_NPC, overmap_buffer, npc_opinion::owed, mission::reserve_random(), npc::set_attitude(), npc::set_fac(), npc_opinion::trust, and npc_opinion::value.

Referenced by cleanup_at_end().

◆ reset_zoom()

void game::reset_zoom ( )

Definition at line 7326 of file game.cpp.

7327{
7328#if defined(TILES)
7330 rescale_tileset( tileset_zoom );
7331#endif // TILES
7332}

References DEFAULT_TILESET_ZOOM, and tileset_zoom.

◆ revive_corpse()

bool game::revive_corpse ( const tripoint p,
item it 
)

Revives a corpse at given location.

The monster type and some of its properties are deducted from the corpse. If reviving succeeds, the location is guaranteed to have a new monster there (see critter_at).

Parameters
pThe place where to put the revived monster.
itThe corpse item, it must be a valid corpse (see item::is_corpse).
Returns
Whether the corpse has actually been redivided. Reviving may fail for many reasons, including no space to put the monster, corpse being to much damaged etc. If the monster was revived, the caller should remove the corpse item. If reviving failed, the item is unchanged, as is the environment (no new monsters).

Definition at line 5153 of file game.cpp.

5154{
5155 if( !it.is_corpse() ) {
5156 debugmsg( "Tried to revive a non-corpse." );
5157 return false;
5158 }
5159 shared_ptr_fast<monster> newmon_ptr = make_shared_fast<monster>
5160 ( it.get_mtype()->id );
5161 monster &critter = *newmon_ptr;
5162 critter.init_from_item( it );
5163 if( critter.get_hp() < 1 ) {
5164 // Failed reanimation due to corpse being too burned
5165 return false;
5166 }
5167 if( it.has_flag( "FIELD_DRESS" ) || it.has_flag( "FIELD_DRESS_FAILED" ) ||
5168 it.has_flag( "QUARTERED" ) ) {
5169 // Failed reanimation due to corpse being butchered
5170 return false;
5171 }
5172
5173 critter.no_extra_death_drops = true;
5174 critter.add_effect( effect_downed, 5_turns, num_bp );
5175 for( const item &component : it.components ) {
5176 critter.corpse_components.push_back( component );
5177 }
5178
5179 if( it.get_var( "zlave" ) == "zlave" ) {
5180 critter.add_effect( effect_pacified, 1_turns, num_bp );
5181 critter.add_effect( effect_pet, 1_turns, num_bp );
5182 }
5183
5184 if( it.get_var( "no_ammo" ) == "no_ammo" ) {
5185 for( auto &ammo : critter.ammo ) {
5186 ammo.second = 0;
5187 }
5188 }
5189
5190 return place_critter_at( newmon_ptr, p );
5191}
monster * place_critter_at(const mtype_id &id, const tripoint &p)
Adds critters to the reality bubble, creating them if necessary.
Definition: game.cpp:4950
const mtype * get_mtype() const
Definition: item.cpp:6398
std::list< item > components
Definition: item.h:2155
bool is_corpse() const
Whether this is a corpse item.
Definition: item.cpp:6393
int get_hp(const bodypart_id &) const override
Definition: monster.cpp:2894
bool no_extra_death_drops
Definition: monster.h:480
std::vector< item > corpse_components
Definition: monster.h:457
void init_from_item(const item &itm)
Initialize values like speed / hp from data of an item.
Definition: monster.cpp:2758
static const efftype_id effect_downed("downed")
static const efftype_id effect_pacified("pacified")

References monster::add_effect(), monster::ammo, item::components, monster::corpse_components, debugmsg, effect_downed, effect_pacified, effect_pet, monster::get_hp(), item::get_mtype(), item::get_var(), item::has_flag(), mtype::id, monster::init_from_item(), item::is_corpse(), monster::no_extra_death_drops, num_bp, and place_critter_at().

◆ save()

bool game::save ( )

Returns false if saving failed.

Definition at line 3095 of file game.cpp.

3096{
3097 try {
3098 if( !save_player_data() ||
3100 !save_artifacts() ||
3101 !save_maps() ||
3102 !get_auto_pickup().save_character() ||
3104 !get_safemode().save_character() ||
3105 !write_to_file( get_world_base_save_path() + "/uistate.json", [&]( std::ostream & fout ) {
3106 JsonOut jsout( fout );
3107 uistate.serialize( jsout );
3108 }, _( "uistate data" ) ) ) {
3109 return false;
3110 } else {
3111 world_generator->active_world->add_save( save_t::from_player_name( u.name ) );
3112 return true;
3113 }
3114 } catch( std::ios::failure &err ) {
3115 popup( _( "Failed to save game data" ) );
3116 return false;
3117 }
3118}
void write_to_file(const std::string &path, const std::function< void(std::ostream &)> &writer)
Definition: json.h:580
bool save_player_data()
Definition: game.cpp:3049
void serialize(JsonOut &json) const
@ failure
Definition: behavior.h:20

References _, behavior::failure, save_t::from_player_name(), get_auto_notes_settings(), get_auto_pickup(), get_safemode(), get_world_base_save_path(), Character::name, popup(), save(), save_artifacts(), save_factions_missions_npcs(), save_maps(), save_player_data(), uistatedata::serialize(), u, uistate, world_generator, and write_to_file().

Referenced by handle_action(), quicksave(), and save().

◆ save_artifacts()

bool game::save_artifacts ( )
private

Definition at line 3030 of file game.cpp.

3031{
3032 std::string artfilename = get_world_base_save_path() + "/" + SAVE_ARTIFACTS;
3033 return ::save_artifacts( artfilename );
3034}
bool save_artifacts(const std::string &path)
Definition: artifact.cpp:1278

References get_world_base_save_path(), SAVE_ARTIFACTS(), and save_artifacts().

Referenced by cleanup_at_end(), and save().

◆ save_cyborg()

void game::save_cyborg ( item cyborg,
const tripoint couch_pos,
player installer 
)

Turns Broken Cyborg monster into Cyborg NPC via surgery.

Definition at line 5193 of file game.cpp.

5194{
5195 int assist_bonus = installer.get_effect_int( effect_assisted );
5196
5197 float adjusted_skill = installer.bionics_adjusted_skill( skill_firstaid,
5200 -1 );
5201
5202 int damage = cyborg->damage();
5203 int dmg_lvl = cyborg->damage_level( 4 );
5204 int difficulty = 12;
5205
5206 if( damage != 0 ) {
5207
5208 popup( _( "WARNING: Patient's body is damaged. Difficulty of the procedure is increased by %s." ),
5209 dmg_lvl );
5210
5211 // Damage of the cyborg increases difficulty
5212 difficulty += dmg_lvl;
5213 }
5214
5215 int chance_of_success = bionic_manip_cos( adjusted_skill + assist_bonus, difficulty );
5216 int success = chance_of_success - rng( 1, 100 );
5217
5218 if( !g->u.query_yn(
5219 _( "WARNING: %i percent chance of SEVERE damage to all body parts! Continue anyway?" ),
5220 100 - static_cast<int>( chance_of_success ) ) ) {
5221 return;
5222 }
5223
5224 if( success > 0 ) {
5225 add_msg( m_good, _( "Successfully removed Personality override." ) );
5226 add_msg( m_bad, _( "Autodoc immediately destroys the CBM upon removal." ) );
5227
5228 m.i_rem( couch_pos, cyborg );
5229
5230 const string_id<npc_template> npc_cyborg( "cyborg_rescued" );
5231 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
5232 tmp->normalize();
5233 tmp->load_npc_template( npc_cyborg );
5234 tmp->spawn_at_precise( { get_levx(), get_levy() }, couch_pos );
5236 tmp->hurtall( dmg_lvl * 10, nullptr );
5237 tmp->add_effect( effect_downed, rng( 1_turns, 4_turns ), num_bp, 0, true );
5238 load_npcs();
5239
5240 } else {
5241 const int failure_level = static_cast<int>( std::sqrt( std::abs( success ) * 4.0 * difficulty /
5242 adjusted_skill ) );
5243 const int fail_type = std::min( 5, failure_level );
5244 switch( fail_type ) {
5245 case 1:
5246 case 2:
5247 add_msg( m_info, _( "The removal fails." ) );
5248 add_msg( m_bad, _( "The body is damaged." ) );
5249 cyborg->set_damage( damage + 1000 );
5250 break;
5251 case 3:
5252 case 4:
5253 add_msg( m_info, _( "The removal fails badly." ) );
5254 add_msg( m_bad, _( "The body is badly damaged!" ) );
5255 cyborg->set_damage( damage + 2000 );
5256 break;
5257 case 5:
5258 add_msg( m_info, _( "The removal is a catastrophe." ) );
5259 add_msg( m_bad, _( "The body is destroyed!" ) );
5260 m.i_rem( couch_pos, cyborg );
5261 break;
5262 default:
5263 break;
5264 }
5265
5266 }
5267
5268}
int bionic_manip_cos(float adjusted_skill, int bionic_difficulty)
Definition: bionics.cpp:1894
float bionics_adjusted_skill(const skill_id &most_important_skill, const skill_id &important_skill, const skill_id &least_important_skill, int skill_level=-1)
Calculate skill for (un)installing bionics.
Definition: bionics.cpp:1851
item & set_damage(int qty)
Filter setting damage constrained by min_damage and max_damage.
Definition: item.cpp:706
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:693
int damage() const
How much damage has the item sustained?
Definition: item.cpp:688
map_stack::iterator i_rem(const tripoint &p, map_stack::const_iterator it)
Definition: map.cpp:4090
static const skill_id skill_computer("computer")
static const efftype_id effect_assisted("assisted")
static const skill_id skill_electronics("electronics")
@ success
Definition: behavior.h:20

References _, add_msg(), bionic_manip_cos(), Character::bionics_adjusted_skill(), item::damage(), item::damage_level(), effect_assisted, effect_downed, g, Creature::get_effect_int(), get_levx(), get_levy(), map::i_rem(), overmapbuffer::insert_npc(), load_npcs(), m, m_bad, m_good, m_info, num_bp, overmap_buffer, popup(), rng(), item::set_damage(), skill_computer, skill_electronics, skill_firstaid, and behavior::success.

◆ save_factions_missions_npcs()

bool game::save_factions_missions_npcs ( )
private

Definition at line 3022 of file game.cpp.

3023{
3024 std::string masterfile = get_world_base_save_path() + "/" + SAVE_MASTER;
3025 return write_to_file( masterfile, [&]( std::ostream & fout ) {
3026 serialize_master( fout );
3027 }, _( "factions data" ) );
3028}
void serialize_master(std::ostream &fout)
Definition: savegame.cpp:1259

References _, get_world_base_save_path(), SAVE_MASTER(), serialize_master(), and write_to_file().

Referenced by cleanup_at_end(), and save().

◆ save_maps()

bool game::save_maps ( )
private

Definition at line 3036 of file game.cpp.

3037{
3038 try {
3039 m.save();
3040 overmap_buffer.save(); // can throw
3041 MAPBUFFER.save(); // can throw
3042 return true;
3043 } catch( const std::exception &err ) {
3044 popup( _( "Failed to save the maps: %s" ), err.what() );
3045 return false;
3046 }
3047}
void save(bool delete_after_save=false)
Store all submaps in this instance into savefiles.
Definition: mapbuffer.cpp:103

References _, m, MAPBUFFER, overmap_buffer, popup(), map::save(), overmapbuffer::save(), and mapbuffer::save().

Referenced by cleanup_at_end(), and save().

◆ save_player_data()

bool game::save_player_data ( )
private

Definition at line 3049 of file game.cpp.

3050{
3051 const std::string playerfile = get_player_base_save_path();
3052
3053 const bool saved_data = write_to_file( playerfile + SAVE_EXTENSION, [&]( std::ostream & fout ) {
3054 serialize( fout );
3055 }, _( "player data" ) );
3056 const bool saved_map_memory = u.save_map_memory();
3057 const bool saved_log = write_to_file( playerfile + SAVE_EXTENSION_LOG, [&](
3058 std::ostream & fout ) {
3059 fout << memorial().dump();
3060 }, _( "player memorial" ) );
3061#if defined(__ANDROID__)
3062 const bool saved_shortcuts = write_to_file( playerfile + SAVE_EXTENSION_SHORTCUTS, [&](
3063 std::ostream & fout ) {
3064 save_shortcuts( fout );
3065 }, _( "quick shortcuts" ) );
3066#endif
3067
3068 return saved_data && saved_map_memory && saved_log
3069#if defined(__ANDROID__)
3070 && saved_shortcuts
3071#endif
3072 ;
3073}
bool save_map_memory()
Definition: avatar.cpp:127
std::string get_player_base_save_path() const
Base path for saving player data.
Definition: game.cpp:12526
void serialize(std::ostream &fout)
Saving and loading functions.
Definition: savegame.cpp:71
std::string dump() const
Concatenates all of the memorial log entries, delimiting them with newlines, and returns the resultin...

References _, memorial_logger::dump(), get_player_base_save_path(), memorial(), SAVE_EXTENSION(), SAVE_EXTENSION_LOG(), SAVE_EXTENSION_SHORTCUTS(), avatar::save_map_memory(), serialize(), u, and write_to_file().

Referenced by save().

◆ serialize()

void game::serialize ( std::ostream &  fout)

Saving and loading functions.

Definition at line 71 of file savegame.cpp.

72{
73 /*
74 * Format version 12: Fully json, save the header. Weather and memorial exist elsewhere.
75 * To prevent (or encourage) confusion, there is no version 8. (cata 0.8 uses v7)
76 */
77 // Header
78 fout << "# version " << savegame_version << std::endl;
79
80 JsonOut json( fout, true ); // pretty-print
81
82 json.start_object();
83 // basic game state information.
84 json.member( "turn", calendar::turn );
86 json.member( "calendar_start", calendar_config._start_of_cataclysm );
87 json.member( "game_start", calendar_config._start_of_game );
88 json.member( "initial_season", static_cast<int>( calendar_config._initial_season ) );
89 json.member( "auto_travel_mode", auto_travel_mode );
90 json.member( "run_mode", static_cast<int>( safe_mode ) );
91 json.member( "mostseen", mostseen );
92 // current map coordinates
93 tripoint pos_sm = m.get_abs_sub();
94 const point pos_om = sm_to_om_remain( pos_sm.x, pos_sm.y );
95 json.member( "levx", pos_sm.x );
96 json.member( "levy", pos_sm.y );
97 json.member( "levz", pos_sm.z );
98 json.member( "om_x", pos_om.x );
99 json.member( "om_y", pos_om.y );
100
101 json.member( "grscent", scent.serialize() );
102 json.member( "typescent", scent.serialize( true ) );
103
104 // Then each monster
105 json.member( "active_monsters", *critter_tracker );
106 json.member( "stair_monsters", coming_to_stairs );
107
108 // save stats.
109 json.member( "kill_tracker", *kill_tracker_ptr );
110 json.member( "stats_tracker", *stats_tracker_ptr );
111 json.member( "achievements_tracker", *achievements_tracker_ptr );
112
113 json.member( "token_provider", *token_provider_ptr );
114
115 json.member( "player", u );
116 Messages::serialize( json );
117
118 json.end_object();
119}
A class that keeps time data other than current time.
Definition: calendar.h:530
season_type _initial_season
Definition: calendar.h:534
time_point _start_of_game
Definition: calendar.h:533
time_point _start_of_cataclysm
Definition: calendar.h:532
pimpl< drop_token_provider > token_provider_ptr
Definition: game.h:1023
std::string serialize(bool is_type=false) const
Definition: savegame.cpp:121
point sm_to_om_remain(int &x, int &y)
void serialize(JsonOut &json)
Definition: messages.cpp:321
calendar_config config
const int savegame_version
Definition: savegame.cpp:59

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, achievements_tracker_ptr, auto_travel_mode, coming_to_stairs, calendar::config, critter_tracker, JsonOut::end_object(), map::get_abs_sub(), kill_tracker_ptr, m, JsonOut::member(), mostseen, safe_mode, savegame_version, scent, scent_map::serialize(), Messages::serialize(), sm_to_om_remain(), JsonOut::start_object(), stats_tracker_ptr, token_provider_ptr, calendar::turn, u, point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

Referenced by save_player_data().

◆ serialize_master()

void game::serialize_master ( std::ostream &  fout)
private

Definition at line 1259 of file savegame.cpp.

1260{
1261 fout << "# version " << savegame_version << std::endl;
1262 try {
1263 JsonOut json( fout, true ); // pretty-print
1264 json.start_object();
1265
1266 json.member( "next_mission_id", next_mission_id );
1267 json.member( "next_npc_id", next_npc_id );
1268
1269 json.member( "active_missions" );
1270 mission::serialize_all( json );
1271
1272 json.member( "factions", *faction_manager_ptr );
1273 json.member( "seed", seed );
1274
1275 json.member( "weather" );
1276 json.start_object();
1277 json.member( "lightning", get_weather().lightning_active );
1278 json.end_object();
1279
1280 json.end_object();
1281 } catch( const JsonError &e ) {
1282 debugmsg( "error saving to %s: %s", SAVE_MASTER, e.c_str() );
1283 }
1284}
Definition: json.h:51
const char * c_str() const noexcept
Definition: json.h:54
static void serialize_all(JsonOut &json)
Definition: savegame.cpp:1250

References JsonError::c_str(), debugmsg, JsonOut::end_object(), faction_manager_ptr, get_weather, JsonOut::member(), next_mission_id, next_npc_id, SAVE_MASTER(), savegame_version, seed, mission::serialize_all(), and JsonOut::start_object().

Referenced by save_factions_missions_npcs().

◆ set_critter_died()

void game::set_critter_died ( )

If invoked, dead will be cleaned this turn.

Definition at line 1871 of file game.cpp.

1872{
1873 critter_died = true;
1874}

References critter_died.

◆ set_driving_view_offset()

void game::set_driving_view_offset ( const point p)

Definition at line 1688 of file game.cpp.

1689{
1690 // remove the previous driving offset,
1691 // store the new offset and apply the new offset.
1698}

References driving_view_offset, u, player::view_offset, point::x, tripoint::x, point::y, and tripoint::y.

Referenced by calc_driving_offset(), and cleanup_at_end().

◆ set_npcs_dirty()

void game::set_npcs_dirty ( )

If invoked, NPCs will be reloaded before next turn.

Definition at line 1866 of file game.cpp.

1867{
1868 npcs_dirty = true;
1869}

References npcs_dirty.

◆ set_safe_mode()

void game::set_safe_mode ( safe_mode_type  mode)

Definition at line 9174 of file game.cpp.

9175{
9176 safe_mode = mode;
9178}

References safe_mode, and safe_mode_warning_logged.

Referenced by handle_action(), and mon_info_update().

◆ set_zoom()

void game::set_zoom ( int  level)

Definition at line 7334 of file game.cpp.

7335{
7336#if defined(TILES)
7337 if( tileset_zoom != level ) {
7338 tileset_zoom = level;
7339 rescale_tileset( tileset_zoom );
7340 }
7341#else
7342 static_cast<void>( level );
7343#endif // TILES
7344}

References tileset_zoom.

Referenced by look_around().

◆ setremoteveh()

void game::setremoteveh ( vehicle veh)

Sets the current remotely controlled vehicle.

Definition at line 2581 of file game.cpp.

2582{
2584 remoteveh_cache = veh;
2585 if( veh != nullptr && !u.has_active_bionic( bio_remote ) &&
2587 debugmsg( "Tried to set remote vehicle without bio_remote or remotevehcontrol" );
2588 veh = nullptr;
2589 }
2590
2591 if( veh == nullptr ) {
2592 u.remove_value( "remote_controlling_vehicle" );
2593 return;
2594 }
2595
2596 std::stringstream remote_veh_string;
2597 const tripoint vehpos = veh->global_pos3();
2598 remote_veh_string << vehpos.x << ' ' << vehpos.y << ' ' << vehpos.z;
2599 u.set_value( "remote_controlling_vehicle", remote_veh_string.str() );
2600}
void remove_value(const std::string &key)
Definition: creature.cpp:1330

References bio_remote, debugmsg, vehicle::global_pos3(), Character::has_active_bionic(), Character::has_active_item(), itype_remotevehcontrol, remoteveh_cache, remoteveh_cache_time, Creature::remove_value(), Creature::set_value(), calendar::turn, u, tripoint::x, tripoint::y, and tripoint::z.

◆ setup()

void game::setup ( )

Definition at line 557 of file game.cpp.

558{
559 loading_ui ui( true );
560 {
563 popup.message( "%s", _( "Please wait while the world data loads…\nLoading core data" ) );
566
568 }
569
571
572 if( get_option<bool>( "ELEVATED_BRIDGES" ) && !get_option<bool>( "ZLEVELS" ) ) {
573 debugmsg( "\"Elevated bridges\" mod requires z-levels to be ENABLED to work properly!" );
574 }
575
576 m = map( get_option<bool>( "ZLEVELS" ) );
577
579 next_mission_id = 1;
580 new_game = true;
581 uquit = QUIT_NO; // We haven't quit the game
582 bVMonsterLookFire = true;
583
584 // invalidate calendar caches in case we were previously playing
585 // a different world
586 calendar::set_eternal_season( ::get_option<bool>( "ETERNAL_SEASON" ) );
587 calendar::set_season_length( ::get_option<int>( "SEASON_LENGTH" ) );
588
591
592 turnssincelastmon = 0; //Auto safe mode init
593
596 coming_to_stairs.clear();
597 active_npc.clear();
598 faction_manager_ptr->clear();
603
604 SCT.vSCT.clear(); //Delete pending messages
605
606 stats().clear();
607 // reset kill counts
608 kill_tracker_ptr->clear();
610 // reset follower list
611 follower_ids.clear();
612 scent.reset();
613
615 remoteveh_cache = nullptr;
616
617 token_provider_ptr->clear();
618 // back to menu for save loading, new game etc
619}
void clear_zombies()
Redirects to the creature_tracker clear() function.
Definition: game.cpp:5027
void load_world_modfiles(loading_ui &ui)
Loads core data and mods from the active world.
Definition: game.cpp:2929
static void clear_all()
Remove all active missions, used to cleanup on exit and before reloading a new game.
Definition: mission.cpp:127
void reset()
Definition: scent_map.cpp:51
static const string_id< weather_type > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
void clear_messages()
Definition: messages.cpp:351
void reset_sounds()
Definition: sounds.cpp:565

References _, achievements_tracker_ptr, active_npc, calendar::before_time_starts, bVMonsterLookFire, character_id, explosion_handler::explosion_queue::clear(), stats_tracker::clear(), mission::clear_all(), Messages::clear_messages(), clear_zombies(), coming_to_stairs, debugmsg, faction_manager_ptr, follower_ids, explosion_handler::get_explosion_queue(), get_weather, kill_tracker_ptr, load_core_data(), load_world_modfiles(), m, new_game, next_mission_id, next_npc_id, weather_manager::nextweather, string_id< weather_type >::NULL_ID(), popup(), QUIT_NO, ui_manager::redraw(), refresh_display(), remoteveh_cache, remoteveh_cache_time, scent_map::reset(), sounds::reset_sounds(), scent, SCT, calendar::set_eternal_season(), calendar::set_season_length(), stats(), timed_events, token_provider_ptr, turnssincelastmon, uquit, scrollingcombattext::vSCT, and weather_manager::weather_id.

Referenced by butcher_submenu(), and quickload().

◆ shared_from()

template<typename T >
template shared_ptr_fast< npc > game::shared_from< npc > ( const T &  critter)

Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature).

The function may return an empty pointer if the given critter is not stored anywhere (e.g. it was allocated on the stack, not stored in the critter_tracker nor in active_npc nor is it u).

Definition at line 4880 of file game.cpp.

4881{
4882 if( static_cast<const Creature *>( &critter ) == static_cast<const Creature *>( &u ) ) {
4883 // u is not stored in a shared_ptr, but it won't go out of scope anyway
4884 return std::dynamic_pointer_cast<T>( u_shared_ptr );
4885 }
4886 if( critter.is_monster() ) {
4887 if( const shared_ptr_fast<monster> mon_ptr = critter_tracker->find( critter.pos() ) ) {
4888 if( static_cast<const Creature *>( mon_ptr.get() ) == static_cast<const Creature *>( &critter ) ) {
4889 return std::dynamic_pointer_cast<T>( mon_ptr );
4890 }
4891 }
4892 }
4893 if( critter.is_npc() ) {
4894 for( auto &cur_npc : active_npc ) {
4895 if( static_cast<const Creature *>( cur_npc.get() ) == static_cast<const Creature *>( &critter ) ) {
4896 return std::dynamic_pointer_cast<T>( cur_npc );
4897 }
4898 }
4899 }
4900 return nullptr;
4901}

References active_npc, critter_tracker, u, and u_shared_ptr.

Referenced by list_monsters(), mon_info_update(), and validate_mounted_npcs().

◆ shift_destination_preview()

void game::shift_destination_preview ( const point delta)

Definition at line 12539 of file game.cpp.

12540{
12541 for( tripoint &p : destination_preview ) {
12542 p += delta;
12543 }
12544}

References destination_preview.

◆ shift_monsters()

void game::shift_monsters ( const tripoint shift)
private

Shift all active monsters, the shift vector is the number of shifted submaps.

Monsters that are outside of the reality bubble after shifting are despawned. Note on z-levels: this works with vertical shifts, but currently all monsters are despawned upon a vertical shift.

Definition at line 11545 of file game.cpp.

11546{
11547 // If either shift argument is non-zero, we're shifting.
11548 if( shift == tripoint_zero ) {
11549 return;
11550 }
11551 for( monster &critter : all_monsters() ) {
11552 if( shift.xy() != point_zero ) {
11553 critter.shift( shift.xy() );
11554 }
11555
11556 if( m.inbounds( critter.pos() ) && ( shift.z == 0 || m.has_zlevels() ) ) {
11557 // We're inbounds, so don't despawn after all.
11558 // No need to shift Z-coordinates, they are absolute
11559 continue;
11560 }
11561 // Either a vertical shift or the critter is now outside of the reality bubble,
11562 // anyway: it must be saved and removed.
11563 despawn_monster( critter );
11564 }
11565 // The order in which zombies are shifted may cause zombies to briefly exist on
11566 // the same square. This messes up the mon_at cache, so we need to rebuild it.
11567 critter_tracker->rebuild_cache();
11568}

References all_monsters(), critter_tracker, despawn_monster(), map::has_zlevels(), map::inbounds(), m, point_zero, tripoint_zero, tripoint::xy(), and tripoint::z.

Referenced by update_map(), vertical_move(), and vertical_shift().

◆ slip_down()

bool game::slip_down ( )

Checks if player is able to successfully climb to/from some terrain and not slip down.

Returns
whether player has slipped down
Dexterity decreases chances of slipping while climbing

Definition at line 12546 of file game.cpp.

12547{
12548 ///\EFFECT_DEX decreases chances of slipping while climbing
12549 int climb = u.dex_cur;
12550 if( u.has_trait( trait_BADKNEES ) ) {
12551 climb = climb / 2;
12552 }
12553 if( one_in( climb ) ) {
12554 add_msg( m_bad, _( "You slip while climbing and fall down again." ) );
12555 if( climb <= 1 ) {
12556 add_msg( m_bad, _( "Climbing is impossible in your current state." ) );
12557 }
12558 return true;
12559 }
12560 return false;
12561}
static const trait_id trait_BADKNEES("BADKNEES")

References _, add_msg(), Character::dex_cur, Character::has_trait(), m_bad, one_in(), trait_BADKNEES, and u.

◆ spawn_hallucination()

bool game::spawn_hallucination ( const tripoint p)

Spawns a hallucination at a determined position.

Attempts to spawn a hallucination at given location.

Returns false if the hallucination couldn't be spawned for whatever reason, such as a monster already in the target square.

Returns
Whether or not a hallucination was successfully spawned.

Definition at line 5038 of file game.cpp.

5039{
5040 if( one_in( 100 ) ) {
5041 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
5042 tmp->normalize();
5043 tmp->randomize( NC_HALLU );
5044 tmp->spawn_at_precise( { get_levx(), get_levy() }, p );
5045 if( !critter_at( p, true ) ) {
5047 load_npcs();
5048 return true;
5049 } else {
5050 return false;
5051 }
5052 }
5053
5055 const shared_ptr_fast<monster> phantasm = make_shared_fast<monster>( mt );
5056 phantasm->hallucination = true;
5057 phantasm->spawn( p );
5058
5059 //Don't attempt to place phantasms inside of other creatures
5060 if( !critter_at( phantasm->pos(), true ) ) {
5061 return critter_tracker->add( phantasm );
5062 } else {
5063 return false;
5064 }
5065}
mtype_id get_valid_hallucination() const
static MonsterGenerator & generator()
npc_class_id NC_HALLU("NC_HALLU")

References critter_at(), critter_tracker, MonsterGenerator::generator(), get_levx(), get_levy(), MonsterGenerator::get_valid_hallucination(), overmapbuffer::insert_npc(), load_npcs(), NC_HALLU, one_in(), and overmap_buffer.

◆ spell_events_subscriber()

spell_events & game::spell_events_subscriber ( )

Definition at line 3090 of file game.cpp.

3091{
3092 return *spell_events_ptr;
3093}

References spell_events_ptr.

◆ start_calendar()

void game::start_calendar ( )

Definition at line 12108 of file game.cpp.

12109{
12110 const bool scen_season = scen->has_flag( "SPR_START" ) || scen->has_flag( "SUM_START" ) ||
12111 scen->has_flag( "AUT_START" ) || scen->has_flag( "WIN_START" ) ||
12112 scen->has_flag( "SUM_ADV_START" );
12113
12115 if( scen_season ) {
12116 // Configured starting date overridden by scenario, calendar_config.start is left as Spring 1
12118 get_option<int>( "INITIAL_TIME" );
12119 calendar_config._start_of_game = calendar::turn_zero + 1_hours * get_option<int>( "INITIAL_TIME" );
12120 if( scen->has_flag( "SPR_START" ) ) {
12122 } else if( scen->has_flag( "SUM_START" ) ) {
12125 } else if( scen->has_flag( "AUT_START" ) ) {
12128 } else if( scen->has_flag( "WIN_START" ) ) {
12131 } else if( scen->has_flag( "SUM_ADV_START" ) ) {
12134 } else {
12135 debugmsg( "The Unicorn" );
12136 }
12137 } else {
12138 // No scenario, so use the starting date+time configured in world options
12139 int initial_days = get_option<int>( "INITIAL_DAY" );
12140 if( initial_days == -1 ) {
12141 // 0 - 363 for a 91 day season
12142 initial_days = rng( 0, get_option<int>( "SEASON_LENGTH" ) * 4 - 1 );
12143 }
12145
12146 // Determine the season based off how long the seasons are set to be
12147 // First take the number of season elapsed up to the starting date, then mod by 4 to get the season of the current year
12148 const int season_number = ( initial_days / get_option<int>( "SEASON_LENGTH" ) ) % 4;
12149 if( season_number == 0 ) {
12151 } else if( season_number == 1 ) {
12153 } else if( season_number == 2 ) {
12155 } else {
12157 }
12158
12160 + 1_hours * get_option<int>( "INITIAL_TIME" )
12161 + 1_days * get_option<int>( "SPAWN_DELAY" );
12162 }
12163
12165}
@ WINTER
Definition: calendar.h:21
@ AUTUMN
Definition: calendar.h:20
@ SUMMER
Definition: calendar.h:19
@ SPRING
Definition: calendar.h:18
time_duration season_length() const
Definition: calendar.h:569
const scenario * scen
Definition: game.h:1030
bool has_flag(const std::string &flag) const
Such as a seasonal start, fiery start, surrounded start, etc.
Definition: scenario.cpp:439

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, AUTUMN, calendar::config, debugmsg, scenario::has_flag(), rng(), scen, calendar_config::season_length(), SPRING, SUMMER, calendar::turn, calendar::turn_zero, and WINTER.

Referenced by start_game().

◆ start_game()

bool game::start_game ( )
private

Definition at line 644 of file game.cpp.

645{
646 if( !gamemode ) {
647 gamemode = std::make_unique<special_game>();
648 }
649
650 seed = rng_bits();
651 new_game = true;
654 safe_mode = ( get_option<bool>( "SAFEMODE" ) ? SAFE_MODE_ON : SAFE_MODE_OFF );
655 mostseen = 0; // ...and mostseen is 0, we haven't seen any monsters yet.
657
659
662 popup.message( "%s", _( "Please wait as we build your world" ) );
665
666 load_master();
667 u.setID( assign_npc_id() ); // should be as soon as possible, but *after* load_master
668
672 do {
673 omtstart = start_loc.find_player_initial_location();
674 if( omtstart == overmap::invalid_tripoint ) {
675 if( query_yn(
676 _( "Try again?\n\nIt may require several attempts until the game finds a valid starting location." ) ) ) {
679 } else {
680 return false;
681 }
682 }
683 } while( omtstart == overmap::invalid_tripoint );
684
685 start_loc.prepare_map( omtstart );
686
687 // Place vehicles spawned by scenario or profession, has to be placed very early to avoid bugs.
688 if( u.starting_vehicle &&
689 !place_vehicle_nearby( u.starting_vehicle, omtstart.xy(), 0, 30,
690 std::vector<std::string> {} ) ) {
691 debugmsg( "could not place starting vehicle" );
692 }
693
694 if( scen->has_map_extra() ) {
695 // Map extras can add monster spawn points and similar and should be done before the main
696 // map is loaded.
697 start_loc.add_map_extra( omtstart, scen->get_map_extra() );
698 }
699
700 // TODO: fix point types
701 tripoint lev = project_to<coords::sm>( omtstart ).raw();
702 // The player is centered in the map, but lev[xyz] refers to the top left point of the map
703 lev.x -= HALF_MAPSIZE;
704 lev.y -= HALF_MAPSIZE;
705 load_map( lev );
706
709 // Do this after the map cache has been built!
710 start_loc.place_player( u );
711 // ...but then rebuild it, because we want visibility cache to avoid spawning monsters in sight
714 // Start the overmap with out immediate neighborhood visible, this needs to be after place_player
716 get_option<int>( "DISTANCE_INITIAL_VISIBILITY" ), 0 );
717
718 u.moves = 0;
719 u.process_turn(); // process_turn adds the initial move points
723 u.next_climate_control_check = calendar::before_time_starts; // Force recheck at startup
725
726 //Reset character safe mode/pickup rules
731
732 //Put some NPCs in there!
733 if( get_option<std::string>( "STARTING_NPC" ) == "always" ||
734 ( get_option<std::string>( "STARTING_NPC" ) == "scenario" &&
735 !g->scen->has_flag( "LONE_START" ) ) ) {
737 }
738 //Load NPCs. Set nearby npcs to active.
739 load_npcs();
740 // Spawn the monsters
741 const bool spawn_near =
742 get_option<bool>( "BLACK_ROAD" ) || g->scen->has_flag( "SUR_START" );
743 // Surrounded start ones
744 if( spawn_near ) {
745 start_loc.surround_with_monsters( omtstart, mongroup_id( "GROUP_ZOMBIE" ), 70 );
746 }
747
748 m.spawn_monsters( !spawn_near ); // Static monsters
749
750 // Make sure that no monsters are near the player
751 // This can happen in lab starts
752 if( !spawn_near ) {
753 for( monster &critter : all_monsters() ) {
754 if( rl_dist( critter.pos(), u.pos() ) <= 5 ||
755 m.clear_path( critter.pos(), u.pos(), 40, 1, 100 ) ) {
756 remove_zombie( critter );
757 }
758 }
759 }
760
761 //Create mutation_category_level
763 //Calculate mutation drench protection stats
766 if( scen->has_flag( "FIRE_START" ) ) {
767 start_loc.burn( omtstart, 3, 3 );
768 }
769 if( scen->has_flag( "INFECTED" ) ) {
771 }
772 if( scen->has_flag( "BAD_DAY" ) ) {
773 u.add_effect( effect_flu, 1000_minutes );
774 u.add_effect( effect_drunk, 270_minutes );
775 u.add_morale( MORALE_FEELING_BAD, -100, -100, 50_minutes, 50_minutes );
776 }
777 if( scen->has_flag( "HELI_CRASH" ) ) {
778 start_loc.handle_heli_crash( u );
779 bool success = false;
780 for( auto v : m.get_vehicles() ) {
781 std::string name = v.v->type.str();
782 std::string search = std::string( "helicopter" );
783 if( name.find( search ) != std::string::npos ) {
784 for( const vpart_reference &vp : v.v->get_any_parts( VPFLAG_CONTROLS ) ) {
785 const tripoint pos = vp.pos();
786 u.setpos( pos );
787
788 // Delete the items that would have spawned here from a "corpse"
789 for( auto sp : v.v->parts_at_relative( vp.mount(), true ) ) {
790 vehicle_stack here = v.v->get_items( sp );
791
792 for( auto iter = here.begin(); iter != here.end(); ) {
793 iter = here.erase( iter );
794 }
795 }
796
797 auto mons = critter_tracker->find( pos );
798 if( mons != nullptr ) {
799 critter_tracker->remove( *mons );
800 }
801
802 success = true;
803 break;
804 }
805 if( success ) {
806 v.v->name = "Bird Wreckage";
807 break;
808 }
809 }
810 }
811 }
812 if( scen->has_flag( "BORDERED" ) ) {
813 overmap &starting_om = get_cur_om();
814 for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) {
815 starting_om.place_special_forced( overmap_special_id( "world" ), { 0, 0, z },
817 }
818
819 }
820 for( auto &e : u.inv_dump() ) {
821 e->set_owner( g->u );
822 }
823 // Now that we're done handling coordinates, ensure the player's submap is in the center of the map
824 update_map( u );
825 // Profession pets
826 for( const mtype_id &elem : u.starting_pets ) {
827 if( monster *const mon = place_critter_around( elem, u.pos(), 5 ) ) {
828 mon->friendly = -1;
829 mon->add_effect( effect_pet, 1_turns, num_bp );
830 } else {
831 add_msg( m_debug, "cannot place starting pet, no space!" );
832 }
833 }
834 // Assign all of this scenario's missions to the player.
835 for( const mission_type_id &m : scen->missions() ) {
836 const auto mission = mission::reserve_new( m, character_id() );
837 mission->assign( u );
838 }
839
840 g->events().send<event_type::game_start>( u.getID() );
841 return true;
842}
body_part random_body_part(bool main_parts_only)
Returns a random body_part token.
Definition: bodypart.cpp:364
bool last_climate_control_ret
Definition: character.h:2270
void drench_mut_calc()
Recalculates mutation drench protection for all bodyparts (ignored/good/neutral stats)
Definition: character.cpp:7781
void set_stamina(int new_stamina)
Definition: character.cpp:7079
time_point next_climate_control_check
Definition: character.h:2269
int get_stamina_max() const
Definition: character.cpp:7070
void set_highest_cat_level()
Recalculates mutation_category_level[] values for the player.
Definition: character.cpp:7758
void default_initialize()
Perform default initialization.
Definition: auto_note.cpp:101
void start_calendar()
Definition: game.cpp:12108
void create_starting_npcs()
Definition: game.cpp:970
overmap & get_cur_om() const
The overmap which contains the center submap of the reality bubble.
Definition: game.cpp:12406
vehicle * place_vehicle_nearby(const vproto_id &id, const point_abs_omt &origin, int min_distance, int max_distance, const std::vector< std::string > &omt_search_types={})
Definition: game.cpp:844
bool clear_path(const tripoint &f, const tripoint &t, int range, int cost_min, int cost_max) const
Check whether there's a direct line of sight between F and T with the additional movecost restraints.
Definition: map.cpp:6374
static mission * reserve_new(const mission_type_id &type, const character_id &npc_id)
Create a new mission of the given type and assign it to the given npc.
Definition: mission.cpp:64
void assign(avatar &u)
Assigns the mission to the player.
Definition: mission.cpp:210
void place_special_forced(const overmap_special_id &special_id, const tripoint_om_omt &p, om_direction::type dir)
Definition: overmap.cpp:2079
bool reveal(const point_abs_omt &center, int radius, int z)
Mark a square area around center on Z-level z as seen.
bool random_start_location
Definition: player.h:686
vproto_id starting_vehicle
Definition: player.h:698
std::vector< mtype_id > starting_pets
Definition: player.h:699
start_location_id start_location
Definition: player.h:687
void clear_character_rules()
bool has_map_extra() const
Definition: scenario.cpp:454
const std::string & get_map_extra() const
Definition: scenario.cpp:458
const std::vector< mission_type_id > & missions() const
Definition: scenario.cpp:462
start_location_id random_start_location() const
Definition: scenario.cpp:232
void burn(const tripoint_abs_omt &omtstart, size_t count, int rad) const
Burn random terrain / furniture with FLAMMABLE or FLAMMABLE_ASH tag.
void surround_with_monsters(const tripoint_abs_omt &omtstart, const mongroup_id &type, float expected_points) const
Adds surround start monsters.
void prepare_map(const tripoint_abs_omt &omtstart) const
Initialize the map at players start location using prepare_map.
void place_player(player &u) const
Place the player somewhere in the reality bubble (g->m).
void handle_heli_crash(player &u) const
tripoint_abs_omt find_player_initial_location() const
Find a suitable start location on the overmap.
void add_map_extra(const tripoint_abs_omt &omtstart, const std::string &map_extra) const
Adds a map extra, see map_extras.h and map_extras.cpp.
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:58
iterator erase(const_iterator it) override
Definition: vehicle.cpp:230
static const efftype_id effect_drunk("drunk")
static const efftype_id effect_infected("infected")
static const efftype_id effect_accumulated_mutagen("accumulated_mutagen")
static const efftype_id effect_flu("flu")
static constexpr int SPRING_TEMPERATURE
Base starting spring temperature in F used for climate, weather and temperature calculation.
void update_weather()
Definition: weather.cpp:1056
const morale_type MORALE_FEELING_BAD("morale_feeling_bad")
static bool search(const ui_adaptor &om_ui, tripoint_abs_omt &curs, const tripoint_abs_omt &orig)
string_id< overmap_special > overmap_special_id
Definition: omdata.h:40
unsigned int rng_bits()
Definition: rng.cpp:12
string_id< MonsterGroup > mongroup_id
Definition: type_id.h:98
@ VPFLAG_CONTROLS
Definition: veh_type.h:41

References _, Creature::add_effect(), start_location::add_map_extra(), Character::add_morale(), add_msg(), all_monsters(), mission::assign(), assign_npc_id(), calendar::before_time_starts, item_stack::begin(), map::build_map_cache(), start_location::burn(), character_id, auto_notes::auto_note_settings::clear(), overmapbuffer::clear(), auto_pickup::player_settings::clear_character_rules(), safemode::clear_character_rules(), map::clear_path(), create_starting_npcs(), critter_tracker, debugmsg, auto_notes::auto_note_settings::default_initialize(), Character::drench_mut_calc(), effect_accumulated_mutagen, effect_drunk, effect_flu, effect_infected, effect_pet, item_stack::end(), vehicle_stack::erase(), start_location::find_player_initial_location(), g, game_start, gamemode, get_auto_notes_settings(), get_auto_pickup(), get_cur_om(), get_levz(), scenario::get_map_extra(), get_safemode(), Character::get_stamina_max(), map::get_vehicles(), get_weather, Character::getID(), Character::global_omt_location(), HALF_MAPSIZE, start_location::handle_heli_crash(), scenario::has_flag(), scenario::has_map_extra(), init_autosave(), Character::inv_dump(), overmap::invalid_tripoint, map::invalidate_map_cache(), Character::last_climate_control_ret, safemode::load_global(), load_map(), load_master(), load_npcs(), m, m_debug, MAPBUFFER, scenario::missions(), MORALE_FEELING_BAD, mostseen, Creature::moves, om_direction::name(), new_game, Character::next_climate_control_check, weather_manager::nextweather, om_direction::north, num_bp, string_id< T >::obj(), overmap_buffer, OVERMAP_DEPTH, OVERMAP_HEIGHT, place_critter_around(), start_location::place_player(), overmap::place_special_forced(), place_vehicle_nearby(), popup(), Character::pos(), start_location::prepare_map(), player::process_turn(), query_yn(), random_body_part(), player::random_start_location, scenario::random_start_location(), ui_manager::redraw(), refresh_display(), remove_zombie(), mission::reserve_new(), mapbuffer::reset(), overmapbuffer::reveal(), rl_dist(), rng_bits(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, scen, overmap_ui::search(), seed, Character::set_highest_cat_level(), Character::set_stamina(), Character::setID(), Character::setpos(), map::spawn_monsters(), SPRING_TEMPERATURE, start_calendar(), player::start_location, player::starting_pets, player::starting_vehicle, behavior::success, start_location::surround_with_monsters(), weather_manager::temperature, calendar::turn, u, update_map(), weather_manager::update_weather(), VPFLAG_CONTROLS, tripoint::x, coords::coord_point< Point, Origin, Scale >::xy(), and tripoint::y.

◆ start_hauling()

void game::start_hauling ( const tripoint pos)

Definition at line 10908 of file game.cpp.

10909{
10910 // Find target items and quantities thereof for the new activity
10911 std::vector<item_location> target_items;
10912 std::vector<int> quantities;
10913
10914 map_stack items = m.i_at( pos );
10915 for( item &it : items ) {
10916 // Liquid cannot be picked up
10917 if( it.made_of( LIQUID ) ) {
10918 continue;
10919 }
10920 target_items.emplace_back( map_cursor( pos ), &it );
10921 // Quantity of 0 means move all
10922 quantities.push_back( 0 );
10923 }
10924
10925 if( target_items.empty() ) {
10926 // Nothing to haul
10927 return;
10928 }
10929
10930 // Whether the destination is inside a vehicle (not supported)
10931 const bool to_vehicle = false;
10932 // Destination relative to the player
10933 const tripoint relative_destination{};
10934
10936 target_items,
10937 quantities,
10938 to_vehicle,
10939 relative_destination
10940 ) ) );
10941}

References Character::assign_activity(), map::i_at(), LIQUID, m, and u.

Referenced by vertical_move(), and walk_move().

◆ stats()

stats_tracker & game::stats ( )

Definition at line 3080 of file game.cpp.

3081{
3082 return *stats_tracker_ptr;
3083}

References stats_tracker_ptr.

Referenced by death_screen(), handle_action(), setup(), and win().

◆ swap_critters()

bool game::swap_critters ( Creature a,
Creature b 
)

Swaps positions of two creatures.

Definition at line 5067 of file game.cpp.

5068{
5069 if( &a == &b ) {
5070 // No need to do anything, but print a debugmsg anyway
5071 debugmsg( "Tried to swap %s with itself", a.disp_name() );
5072 return true;
5073 }
5074 if( critter_at( a.pos() ) != &a ) {
5075 debugmsg( "Tried to swap when it would cause a collision between %s and %s.",
5076 b.disp_name(), critter_at( a.pos() )->disp_name() );
5077 return false;
5078 }
5079 if( critter_at( b.pos() ) != &b ) {
5080 debugmsg( "Tried to swap when it would cause a collision between %s and %s.",
5081 a.disp_name(), critter_at( b.pos() )->disp_name() );
5082 return false;
5083 }
5084 // Simplify by "sorting" the arguments
5085 // Only the first argument can be u
5086 // If swapping player/npc with a monster, monster is second
5087 bool a_first = a.is_player() ||
5088 ( a.is_npc() && !b.is_player() );
5089 Creature &first = a_first ? a : b;
5090 Creature &second = a_first ? b : a;
5091 // Possible options:
5092 // both first and second are monsters
5093 // second is a monster, first is a player or an npc
5094 // first is a player, second is an npc
5095 // both first and second are npcs
5096 if( first.is_monster() ) {
5097 monster *m1 = dynamic_cast< monster * >( &first );
5098 monster *m2 = dynamic_cast< monster * >( &second );
5099 if( m1 == nullptr || m2 == nullptr || m1 == m2 ) {
5100 debugmsg( "Couldn't swap two monsters" );
5101 return false;
5102 }
5103
5104 critter_tracker->swap_positions( *m1, *m2 );
5105 return true;
5106 }
5107
5108 player *u_or_npc = dynamic_cast< player * >( &first );
5109 player *other_npc = dynamic_cast< player * >( &second );
5110
5111 if( u_or_npc->in_vehicle ) {
5112 g->m.unboard_vehicle( u_or_npc->pos() );
5113 }
5114
5115 if( other_npc && other_npc->in_vehicle ) {
5116 g->m.unboard_vehicle( other_npc->pos() );
5117 }
5118
5119 tripoint temp = second.pos();
5120 second.setpos( first.pos() );
5121
5122 if( first.is_player() ) {
5123 g->walk_move( temp );
5124 } else {
5125 first.setpos( temp );
5126 if( g->m.veh_at( u_or_npc->pos() ).part_with_feature( VPFLAG_BOARDABLE, true ) ) {
5127 g->m.board_vehicle( u_or_npc->pos(), u_or_npc );
5128 }
5129 }
5130
5131 if( other_npc && g->m.veh_at( other_npc->pos() ).part_with_feature( VPFLAG_BOARDABLE, true ) ) {
5132 g->m.board_vehicle( other_npc->pos(), other_npc );
5133 }
5134 return true;
5135}
virtual bool is_monster() const
Definition: creature.h:101
virtual bool is_player() const
Definition: creature.h:92
virtual void setpos(const tripoint &pos)=0
@ VPFLAG_BOARDABLE
Definition: veh_type.h:39

References a, b, critter_at(), critter_tracker, debugmsg, g, Character::in_vehicle, Creature::is_monster(), Creature::is_player(), Creature::pos(), Character::pos(), second, Creature::setpos(), and VPFLAG_BOARDABLE.

Referenced by npc_menu().

◆ take_screenshot() [1/2]

bool game::take_screenshot ( ) const

Saves a screenshot of the current viewport, as a PNG file.

Filesystem location is derived from the current world and character.

Note
: Only works for SDL/TILES (otherwise the function returns false). A window (more precisely, a viewport) must already exist and the SDL renderer must be valid.
Returns
true if the screenshot generation was successful, false otherwise.

Definition at line 7403 of file game.cpp.

7404{
7405 popup( _( "This binary was not compiled with tiles support." ) );
7406 return false;
7407}

References _, and popup().

Referenced by do_turn().

◆ take_screenshot() [2/2]

bool game::take_screenshot ( const std::string &  file_path) const

Saves a screenshot of the current viewport, as a PNG file, to the given location.

Parameters
file_pathA full path to the file where the screenshot should be saved.
Note
: Only works for SDL/TILES (otherwise the function returns false). A window (more precisely, a viewport) must already exist and the SDL renderer must be valid.
Returns
true if the screenshot generation was successful, false otherwise.

Definition at line 7397 of file game.cpp.

7398{
7399 popup( _( "This binary was not compiled with tiles support." ) );
7400 return false;
7401}

References _, and popup().

◆ temp_exit_fullscreen()

void game::temp_exit_fullscreen ( )

Definition at line 535 of file game.cpp.

536{
537 if( fullscreen ) {
538 was_fullscreen = true;
540 } else {
541 was_fullscreen = false;
542 }
543}

References fullscreen, toggle_fullscreen(), and was_fullscreen.

Referenced by list_items_monsters(), and look_around().

◆ toggle_debug_hour_timer()

void game::toggle_debug_hour_timer ( )

Definition at line 11716 of file game.cpp.

11717{
11719}

References game::debug_hour_timer::toggle().

Referenced by handle_action(), and look_around().

◆ toggle_fullscreen()

void game::toggle_fullscreen ( )

Definition at line 497 of file game.cpp.

498{
499#if !defined(TILES)
502#else
503 toggle_fullscreen_window();
504#endif
505}

References fullscreen, and mark_main_ui_adaptor_resize().

Referenced by handle_action(), reenter_fullscreen(), and temp_exit_fullscreen().

◆ toggle_pixel_minimap()

void game::toggle_pixel_minimap ( )

Definition at line 507 of file game.cpp.

508{
509#if defined(TILES)
511 clear_window_area( w_pixel_minimap );
512 }
515#endif // TILES
516}

References mark_main_ui_adaptor_resize(), pixel_minimap_option, and w_pixel_minimap.

Referenced by handle_action(), and look_around().

◆ try_get_left_click_action()

bool game::try_get_left_click_action ( action_id act,
const tripoint mouse_target 
)
private

Definition at line 2602 of file game.cpp.

2603{
2604 bool new_destination = true;
2605 if( !destination_preview.empty() ) {
2606 auto &final_destination = destination_preview.back();
2607 if( final_destination.x == mouse_target.x && final_destination.y == mouse_target.y ) {
2608 // Second click
2609 new_destination = false;
2611 destination_preview.clear();
2613 if( act == ACTION_NULL ) {
2614 // Something went wrong
2616 return false;
2617 }
2618 }
2619 }
2620
2621 if( new_destination ) {
2623 u.get_path_avoid() );
2624 return false;
2625 }
2626
2627 return true;
2628}

References act, ACTION_NULL, Character::clear_destination(), destination_preview, Character::get_next_auto_move_direction(), Character::get_path_avoid(), Character::get_pathfinding_settings(), m, Character::pos(), map::route(), Character::set_destination(), u, tripoint::x, and tripoint::y.

Referenced by handle_action().

◆ try_get_right_click_action()

bool game::try_get_right_click_action ( action_id act,
const tripoint mouse_target 
)
private

Definition at line 2630 of file game.cpp.

2631{
2632 const bool cleared_destination = !destination_preview.empty();
2634 destination_preview.clear();
2635
2636 if( cleared_destination ) {
2637 // Produce no-op if auto-move had just been cleared on this action
2638 // e.g. from a previous single left mouse click. This has the effect
2639 // of right-click canceling an auto-move before it is initiated.
2640 return false;
2641 }
2642
2643 const bool is_adjacent = square_dist( mouse_target.xy(), point( u.posx(), u.posy() ) ) <= 1;
2644 const bool is_self = square_dist( mouse_target.xy(), point( u.posx(), u.posy() ) ) <= 0;
2645 if( const monster *const mon = critter_at<monster>( mouse_target ) ) {
2646 if( !u.sees( *mon ) ) {
2647 add_msg( _( "Nothing relevant here." ) );
2648 return false;
2649 }
2650
2651 if( !u.weapon.is_gun() ) {
2652 add_msg( m_info, _( "You are not wielding a ranged weapon." ) );
2653 return false;
2654 }
2655
2656 // TODO: Add weapon range check. This requires weapon to be reloaded.
2657
2658 act = ACTION_FIRE;
2659 } else if( is_adjacent &&
2660 m.close_door( tripoint( mouse_target.xy(), u.posz() ), !m.is_outside( u.pos() ),
2661 true ) ) {
2662 act = ACTION_CLOSE;
2663 } else if( is_self ) {
2665 } else if( is_adjacent ) {
2667 } else {
2668 add_msg( _( "Nothing relevant here." ) );
2669 return false;
2670 }
2671
2672 return true;
2673}
bool close_door(const tripoint &p, bool inside, bool check_only)
Definition: map.cpp:3961
static bool is_adjacent(const monster &z, const Creature &target)

References _, act, ACTION_CLOSE, ACTION_EXAMINE, ACTION_FIRE, ACTION_PICKUP, add_msg(), Character::clear_destination(), map::close_door(), destination_preview, is_adjacent(), item::is_gun(), map::is_outside(), m, m_info, Character::pos(), Character::posx(), Character::posy(), Character::posz(), Character::sees(), square_dist(), u, Character::weapon, and tripoint::xy().

Referenced by handle_action().

◆ unload()

bool game::unload ( item_location  loc)

Definition at line 9008 of file game.cpp.

9009{
9010 return u.unload( loc );
9011}
bool unload(item_location loc)
Definition: player.cpp:3090

References u, and player::unload().

Referenced by inventory_item_menu().

◆ unload_npcs()

void game::unload_npcs ( )
private

Unloads all NPCs.

If you call this you must later call load_npcs, lest caches get rather confused. The tests used to call this a lot when they shouldn't. It is now private to reduce the chance of similar problems in the future.

Definition at line 948 of file game.cpp.

949{
950 for( const auto &npc : active_npc ) {
951 npc->on_unload();
952 }
953
954 active_npc.clear();
955}
void on_unload()
Do some cleanup and caching as npc is being unloaded from map.
Definition: npc.cpp:2642

References active_npc, and npc::on_unload().

Referenced by place_player_overmap(), and reload_npcs().

◆ unserialize()

void game::unserialize ( std::istream &  fin)

Definition at line 169 of file savegame.cpp.

170{
171 chkversion( fin );
172 int tmpturn = 0;
173 int tmpcalstart = 0;
174 int tmprun = 0;
175 tripoint lev;
176 point com;
177 JsonIn jsin( fin );
178 try {
179 JsonObject data = jsin.get_object();
180
181 data.read( "turn", tmpturn );
182 data.read( "calendar_start", tmpcalstart );
184 calendar_config._initial_season = static_cast<season_type>( data.get_int( "initial_season",
185 static_cast<int>( SPRING ) ) );
186 // 0.E stable
187 if( savegame_loading_version < 26 ) {
188 tmpturn *= 6;
189 tmpcalstart *= 6;
190 }
193 tmpcalstart );
194
195 if( !data.read( "game_start", calendar_config._start_of_game ) ) {
197 }
198
199 data.read( "auto_travel_mode", auto_travel_mode );
200 data.read( "run_mode", tmprun );
201 data.read( "mostseen", mostseen );
202 data.read( "levx", lev.x );
203 data.read( "levy", lev.y );
204 data.read( "levz", lev.z );
205 data.read( "om_x", com.x );
206 data.read( "om_y", com.y );
207
208 load_map( tripoint( lev.x + com.x * OMAPX * 2, lev.y + com.y * OMAPY * 2, lev.z ) );
209
210 safe_mode = static_cast<safe_mode_type>( tmprun );
211 if( get_option<bool>( "SAFEMODE" ) && safe_mode == SAFE_MODE_OFF ) {
213 }
214
215 std::string linebuff;
216 std::string linebuf;
217 if( data.read( "grscent", linebuf ) && data.read( "typescent", linebuff ) ) {
218 scent.deserialize( linebuf );
219 scent.deserialize( linebuff, true );
220 } else {
221 scent.reset();
222 }
223 data.read( "active_monsters", *critter_tracker );
224
225 coming_to_stairs.clear();
226 for( auto elem : data.get_array( "stair_monsters" ) ) {
227 monster stairtmp;
228 elem.read( stairtmp );
229 coming_to_stairs.push_back( stairtmp );
230 }
231
232 if( data.has_object( "kill_tracker" ) ) {
233 data.read( "kill_tracker", *kill_tracker_ptr );
234 } else {
235 // Legacy support for when kills were stored directly in game
236 std::map<mtype_id, int> kills;
237 std::vector<std::string> npc_kills;
238 for( const JsonMember member : data.get_object( "kills" ) ) {
239 kills[mtype_id( member.name() )] = member.get_int();
240 }
241
242 for( const std::string npc_name : data.get_array( "npc_kills" ) ) {
243 npc_kills.push_back( npc_name );
244 }
245
246 kill_tracker_ptr->reset( kills, npc_kills );
247 }
248
249 data.read( "player", u );
250 data.read( "stats_tracker", *stats_tracker_ptr );
251 data.read( "achievements_tracker", *achievements_tracker_ptr );
252 data.read( "token_provider", token_provider_ptr );
253 Messages::deserialize( data );
254
255 } catch( const JsonError &jsonerr ) {
256 debugmsg( "Bad save json\n%s", jsonerr.c_str() );
257 return;
258 }
259}
season_type
Real world seasons.
Definition: calendar.h:17
Represents a member of a JsonObject.
Definition: json.h:1249
JsonObject get_object(const std::string &name) const
Definition: json.cpp:361
bool has_object(const std::string &name) const
Definition: json.cpp:425
JsonArray get_array(const std::string &name) const
Definition: json.cpp:332
int get_int(const std::string &name) const
Definition: json.cpp:282
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:944
void deserialize(const std::string &data, bool is_type=false)
Definition: savegame.cpp:261
safe_mode_type
Definition: game.h:76
static constexpr int OMAPY
static constexpr int OMAPX
Size of the overmap.
void deserialize(const JsonObject &json)
Definition: messages.cpp:330
std::string member
Definition: mapgen.cpp:402
static void chkversion(std::istream &fin)
Definition: savegame.cpp:150
int savegame_loading_version
Definition: savegame.cpp:66

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, achievements_tracker_ptr, auto_travel_mode, JsonError::c_str(), chkversion(), coming_to_stairs, calendar::config, critter_tracker, debugmsg, Messages::deserialize(), scent_map::deserialize(), time_duration::from_turns(), JsonObject::get_array(), JsonObject::get_int(), JsonIn::get_object(), JsonObject::get_object(), JsonObject::has_object(), kill_tracker_ptr, load_map(), mapgen_defer::member, mostseen, mtype_id, OMAPX, OMAPY, JsonObject::read(), scent_map::reset(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, savegame_loading_version, scent, SPRING, stats_tracker_ptr, token_provider_ptr, calendar::turn, calendar::turn_zero, u, point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

Referenced by load().

◆ unserialize_master()

void game::unserialize_master ( std::istream &  fin)

Definition at line 1209 of file savegame.cpp.

1210{
1212 chkversion( fin );
1213 if( savegame_loading_version < 11 ) {
1214 std::unique_ptr<static_popup>popup = std::make_unique<static_popup>();
1215 popup->message(
1216 _( "Cannot find loader for save data in old version %d, attempting to load as current version %d." ),
1220 }
1221 try {
1222 // single-pass parsing example
1223 JsonIn jsin( fin );
1224 jsin.start_object();
1225 while( !jsin.end_object() ) {
1226 std::string name = jsin.get_member_name();
1227 if( name == "next_mission_id" ) {
1228 next_mission_id = jsin.get_int();
1229 } else if( name == "next_npc_id" ) {
1230 next_npc_id.deserialize( jsin );
1231 } else if( name == "active_missions" ) {
1233 } else if( name == "factions" ) {
1234 jsin.read( *faction_manager_ptr );
1235 } else if( name == "seed" ) {
1236 jsin.read( seed );
1237 } else if( name == "weather" ) {
1238 JsonObject w = jsin.get_object();
1239 w.read( "lightning", get_weather().lightning_active );
1240 } else {
1241 // silently ignore anything else
1242 jsin.skip_value();
1243 }
1244 }
1245 } catch( const JsonError &e ) {
1246 debugmsg( "error loading %s: %s", SAVE_MASTER, e.c_str() );
1247 }
1248}
void deserialize(JsonIn &)
static void unserialize_all(JsonIn &jsin)
Definition: savegame.cpp:1199

References _, JsonError::c_str(), chkversion(), debugmsg, character_id::deserialize(), JsonIn::end_object(), faction_manager_ptr, JsonIn::get_int(), JsonIn::get_member_name(), JsonIn::get_object(), get_weather, om_direction::name(), next_mission_id, next_npc_id, popup(), JsonIn::read(), JsonObject::read(), ui_manager::redraw(), refresh_display(), SAVE_MASTER(), savegame_loading_version, savegame_version, seed, JsonIn::skip_value(), JsonIn::start_object(), and mission::unserialize_all().

Referenced by load_master().

◆ update_map() [1/2]

point game::update_map ( int &  x,
int &  y 
)

Definition at line 11176 of file game.cpp.

11177{
11178 point shift;
11179
11180 while( x < HALF_MAPSIZE_X ) {
11181 x += SEEX;
11182 shift.x--;
11183 }
11184 while( x >= HALF_MAPSIZE_X + SEEX ) {
11185 x -= SEEX;
11186 shift.x++;
11187 }
11188 while( y < HALF_MAPSIZE_Y ) {
11189 y += SEEY;
11190 shift.y--;
11191 }
11192 while( y >= HALF_MAPSIZE_Y + SEEY ) {
11193 y -= SEEY;
11194 shift.y++;
11195 }
11196
11197 if( shift == point_zero ) {
11198 // adjust player position
11199 u.setpos( tripoint( x, y, get_levz() ) );
11200 // Update what parts of the world map we can see
11201 // We need this call because even if the map hasn't shifted we may have changed z-level and can now see farther
11202 // TODO: only make this call if we changed z-level
11204 // Not actually shifting the submaps, all the stuff below would do nothing
11205 return point_zero;
11206 }
11207
11208 // this handles loading/unloading submaps that have scrolled on or off the viewport
11209 // NOLINTNEXTLINE(cata-use-named-point-constants)
11210 inclusive_rectangle<point> size_1( point( -1, -1 ), point( 1, 1 ) );
11211 point remaining_shift = shift;
11212 while( remaining_shift != point_zero ) {
11213 point this_shift = clamp( remaining_shift, size_1 );
11214 m.shift( this_shift );
11215 remaining_shift -= this_shift;
11216 }
11217
11218 grid_tracker_ptr->load( m );
11219
11220 // Shift monsters
11221 shift_monsters( tripoint( shift, 0 ) );
11222 const point shift_ms = sm_to_ms_copy( shift );
11223 u.shift_destination( -shift_ms );
11224
11225 // Shift NPCs
11226 for( auto it = active_npc.begin(); it != active_npc.end(); ) {
11227 ( *it )->shift( shift );
11228 if( ( *it )->posx() < 0 - SEEX * 2 || ( *it )->posy() < 0 - SEEX * 2 ||
11229 ( *it )->posx() > SEEX * ( MAPSIZE + 2 ) || ( *it )->posy() > SEEY * ( MAPSIZE + 2 ) ) {
11230 //Remove the npc from the active list. It remains in the overmap list.
11231 ( *it )->on_unload();
11232 it = active_npc.erase( it );
11233 } else {
11234 it++;
11235 }
11236 }
11237
11238 scent.shift( shift_ms );
11239
11240 // Also ensure the player is on current z-level
11241 // get_levz() should later be removed, when there is no longer such a thing
11242 // as "current z-level"
11243 u.setpos( tripoint( x, y, get_levz() ) );
11244
11245 // Only do the loading after all coordinates have been shifted.
11246
11247 // Check for overmap saved npcs that should now come into view.
11248 // Put those in the active list.
11249 load_npcs();
11250
11251 // Make sure map cache is consistent since it may have shifted.
11252 if( m.has_zlevels() ) {
11253 for( int zlev = -OVERMAP_DEPTH; zlev <= OVERMAP_HEIGHT; ++zlev ) {
11254 m.invalidate_map_cache( zlev );
11255 }
11256 } else {
11258 }
11260
11261 // Spawn monsters if appropriate
11262 // This call will generate new monsters in addition to loading, so it's placed after NPC loading
11263 m.spawn_monsters( false ); // Static monsters
11264
11265 // Update what parts of the world map we can see
11267
11268 return shift;
11269}
void shift_destination(const point &shift)
void shift_monsters(const tripoint &shift)
Shift all active monsters, the shift vector is the number of shifted submaps.
Definition: game.cpp:11545
void shift(const point &s)
Shift the map along the vector s.
Definition: map.cpp:6615
void shift(const point &sm_shift)
Definition: scent_map.cpp:82
point sm_to_ms_copy(const point &p)
static constexpr int HALF_MAPSIZE_Y
static constexpr int HALF_MAPSIZE_X

References active_npc, map::build_map_cache(), clamp(), get_levz(), grid_tracker_ptr, HALF_MAPSIZE_X, HALF_MAPSIZE_Y, map::has_zlevels(), map::invalidate_map_cache(), load_npcs(), m, MAPSIZE, OVERMAP_DEPTH, OVERMAP_HEIGHT, point_zero, scent, SEEX, SEEY, Character::setpos(), map::shift(), scent_map::shift(), Character::shift_destination(), shift_monsters(), sm_to_ms_copy(), map::spawn_monsters(), u, update_overmap_seen(), point::x, and point::y.

◆ update_map() [2/2]

point game::update_map ( player p)

Definition at line 11170 of file game.cpp.

11171{
11172 point p2( p.posx(), p.posy() );
11173 return update_map( p2.x, p2.y );
11174}

References Character::posx(), Character::posy(), update_map(), point::x, and point::y.

Referenced by fling_creature(), load(), place_player(), start_game(), update_map(), and vertical_move().

◆ update_overmap_seen()

void game::update_overmap_seen ( )

Definition at line 11271 of file game.cpp.

11272{
11273 const tripoint_abs_omt ompos = u.global_omt_location();
11274 const int dist = u.overmap_sight_range( light_level( u.posz() ) );
11275 const int dist_squared = dist * dist;
11276 // We can always see where we're standing
11277 overmap_buffer.set_seen( ompos, true );
11278 for( const tripoint_abs_omt &p : points_in_radius( ompos, dist ) ) {
11279 const point_rel_omt delta = p.xy() - ompos.xy();
11280 const int h_squared = delta.x() * delta.x() + delta.y() * delta.y();
11281 if( trigdist && h_squared > dist_squared ) {
11282 continue;
11283 }
11284 if( delta == point_rel_omt() ) {
11285 // 1. This case is already handled outside of the loop
11286 // 2. Calculating multiplier would cause division by zero
11287 continue;
11288 }
11289 // If circular distances are enabled, scale overmap distances by the diagonality of the sight line.
11290 point abs_delta = delta.raw().abs();
11291 int max_delta = std::max( abs_delta.x, abs_delta.y );
11292 const float multiplier = trigdist ? std::sqrt( h_squared ) / max_delta : 1;
11293 const std::vector<tripoint_abs_omt> line = line_to( ompos, p );
11294 float sight_points = dist;
11295 for( auto it = line.begin();
11296 it != line.end() && sight_points >= 0; ++it ) {
11297 const oter_id &ter = overmap_buffer.ter( *it );
11298 sight_points -= static_cast<int>( ter->get_see_cost() ) * multiplier;
11299 }
11300 if( sight_points >= 0 ) {
11301 tripoint_abs_omt seen( p );
11302 do {
11303 overmap_buffer.set_seen( seen, true );
11304 --seen.z();
11305 } while( seen.z() >= 0 );
11306 }
11307 }
11308}
bool trigdist
Circular distances.
int overmap_sight_range(int light_level) const
Returns the distance the player can see on the overmap.
Definition: character.cpp:759
constexpr Point & raw()
Definition: coordinates.h:111
void set_seen(const tripoint_abs_omt &p, bool seen=true)
coords::coord_point< point, coords::origin::relative, coords::omt > point_rel_omt
Definition: coordinates.h:478
tripoint_range< Tripoint > points_in_radius(const Tripoint &center, const int radius, const int radiusz=0)
Definition: map_iterator.h:125
unsigned char get_see_cost() const
Definition: omdata.h:304

References oter_t::get_see_cost(), Character::global_omt_location(), light_level(), line(), line_to(), overmap_buffer, Character::overmap_sight_range(), points_in_radius(), Character::posz(), coords::coord_point< Point, Origin, Scale >::raw(), overmapbuffer::set_seen(), overmapbuffer::ter(), trigdist, u, coords::coord_point< Point, Origin, Scale >::x(), point::x, coords::coord_point< Point, Origin, Scale >::xy(), coords::coord_point< Point, Origin, Scale >::y(), point::y, and coords::coord_point< Point, Origin, Scale >::z().

Referenced by place_player_overmap(), and update_map().

◆ update_stair_monsters()

void game::update_stair_monsters ( )
private
Dodge reduces chance of being downed when pushed off the stairs

Definition at line 11323 of file game.cpp.

11324{
11325 // Search for the stairs closest to the player.
11326 std::vector<int> stairx;
11327 std::vector<int> stairy;
11328 std::vector<int> stairdist;
11329
11330 const bool from_below = monstairz < get_levz();
11331
11332 if( coming_to_stairs.empty() ) {
11333 return;
11334 }
11335
11336 if( m.has_zlevels() ) {
11337 debugmsg( "%d monsters coming to stairs on a map with z-levels",
11338 coming_to_stairs.size() );
11339 coming_to_stairs.clear();
11340 }
11341
11342 for( const tripoint &dest : m.points_on_zlevel( u.posz() ) ) {
11343 if( ( from_below && m.has_flag( "GOES_DOWN", dest ) ) ||
11344 ( !from_below && m.has_flag( "GOES_UP", dest ) ) ) {
11345 stairx.push_back( dest.x );
11346 stairy.push_back( dest.y );
11347 stairdist.push_back( rl_dist( dest, u.pos() ) );
11348 }
11349 }
11350 if( stairdist.empty() ) {
11351 return; // Found no stairs?
11352 }
11353
11354 // Find closest stairs.
11355 size_t si = 0;
11356 for( size_t i = 0; i < stairdist.size(); i++ ) {
11357 if( stairdist[i] < stairdist[si] ) {
11358 si = i;
11359 }
11360 }
11361
11362 // Find up to 4 stairs for distance stairdist[si] +1
11363 std::vector<int> nearest;
11364 nearest.push_back( si );
11365 for( size_t i = 0; i < stairdist.size() && nearest.size() < 4; i++ ) {
11366 if( ( i != si ) && ( stairdist[i] <= stairdist[si] + 1 ) ) {
11367 nearest.push_back( i );
11368 }
11369 }
11370 // Randomize the stair choice
11371 si = random_entry_ref( nearest );
11372
11373 // Attempt to spawn zombies.
11374 for( size_t i = 0; i < coming_to_stairs.size(); i++ ) {
11375 point mpos( stairx[si], stairy[si] );
11376 monster &critter = coming_to_stairs[i];
11377 const tripoint dest {
11378 mpos, g->get_levz()
11379 };
11380
11381 // We might be not be visible.
11382 if( ( critter.posx() < 0 - ( MAPSIZE_X ) / 6 ||
11383 critter.posy() < 0 - ( MAPSIZE_Y ) / 6 ||
11384 critter.posx() > ( MAPSIZE_X * 7 ) / 6 ||
11385 critter.posy() > ( MAPSIZE_Y * 7 ) / 6 ) ) {
11386 continue;
11387 }
11388
11389 critter.staircount -= 4;
11390 // Let the player know zombies are trying to come.
11391 if( u.sees( dest ) ) {
11392 std::string dump;
11393 if( critter.staircount > 4 ) {
11394 dump += string_format( _( "You see a %s on the stairs" ), critter.name() );
11395 } else {
11396 if( critter.staircount > 0 ) {
11397 dump += ( from_below ?
11398 //~ The <monster> is almost at the <bottom/top> of the <terrain type>!
11399 string_format( _( "The %1$s is almost at the top of the %2$s!" ),
11400 critter.name(),
11401 m.tername( dest ) ) :
11402 string_format( _( "The %1$s is almost at the bottom of the %2$s!" ),
11403 critter.name(),
11404 m.tername( dest ) ) );
11405 }
11406 }
11407
11408 add_msg( m_warning, dump );
11409 } else {
11411 _( "a sound nearby from the stairs!" ), true, "misc", "stairs_movement" );
11412 }
11413
11414 if( critter.staircount > 0 ) {
11415 continue;
11416 }
11417
11418 if( is_empty( dest ) ) {
11419 critter.spawn( dest );
11420 critter.staircount = 0;
11421 place_critter_at( make_shared_fast<monster>( critter ), dest );
11422 if( u.sees( dest ) ) {
11423 if( !from_below ) {
11424 add_msg( m_warning, _( "The %1$s comes down the %2$s!" ),
11425 critter.name(),
11426 m.tername( dest ) );
11427 } else {
11428 add_msg( m_warning, _( "The %1$s comes up the %2$s!" ),
11429 critter.name(),
11430 m.tername( dest ) );
11431 }
11432 }
11433 coming_to_stairs.erase( coming_to_stairs.begin() + i );
11434 continue;
11435 } else if( u.pos() == dest ) {
11436 // Monster attempts to push player of stairs
11438 int tries = 0;
11439
11440 // the critter is now right on top of you and will attack unless
11441 // it can find a square to push you into with one of his tries.
11442 const int creature_push_attempts = 9;
11443 const int player_throw_resist_chance = 3;
11444
11445 critter.spawn( dest );
11446 while( tries < creature_push_attempts ) {
11447 tries++;
11448 push.x = rng( -1, 1 );
11449 push.y = rng( -1, 1 );
11450 point ipos( mpos + push );
11451 tripoint pos( ipos, get_levz() );
11452 if( ( push.x != 0 || push.y != 0 ) && !critter_at( pos ) &&
11453 critter.can_move_to( pos ) ) {
11454 bool resiststhrow = ( u.is_throw_immune() ) ||
11456 if( resiststhrow && one_in( player_throw_resist_chance ) ) {
11457 u.moves -= 25; // small charge for avoiding the push altogether
11458 add_msg( _( "The %s fails to push you back!" ),
11459 critter.name() );
11460 return; //judo or leg brace prevent you from getting pushed at all
11461 }
11462 // Not accounting for tentacles latching on, so..
11463 // Something is about to happen, lets charge half a move
11464 u.moves -= 50;
11465 if( resiststhrow && ( u.is_throw_immune() ) ) {
11466 //we have a judoka who isn't getting pushed but counterattacking now.
11467 mattack::thrown_by_judo( &critter );
11468 return;
11469 }
11470 std::string msg;
11471 ///\EFFECT_DODGE reduces chance of being downed when pushed off the stairs
11472 if( !( resiststhrow ) && ( u.get_dodge() + rng( 0, 3 ) < 12 ) ) {
11473 // dodge 12 - never get downed
11474 // 11.. avoid 75%; 10.. avoid 50%; 9.. avoid 25%
11475 u.add_effect( effect_downed, 2_turns );
11476 msg = _( "The %s pushed you back hard!" );
11477 } else {
11478 msg = _( "The %s pushed you back!" );
11479 }
11480 add_msg( m_warning, msg.c_str(), critter.name() );
11481 u.setx( u.posx() + push.x );
11482 u.sety( u.posy() + push.y );
11483 return;
11484 }
11485 }
11487 _( "The %s tried to push you back but failed! It attacks you!" ),
11488 critter.name() );
11489 critter.melee_attack( u );
11490 u.moves -= 50;
11491 return;
11492 } else if( monster *const mon_ptr = critter_at<monster>( dest ) ) {
11493 // Monster attempts to displace a monster from the stairs
11494 monster &other = *mon_ptr;
11495 critter.spawn( dest );
11496
11497 // the critter is now right on top of another and will push it
11498 // if it can find a square to push it into inside of his tries.
11499 const int creature_push_attempts = 9;
11500 const int creature_throw_resist = 4;
11501
11502 int tries = 0;
11503 point push2;
11504 while( tries < creature_push_attempts ) {
11505 tries++;
11506 push2.x = rng( -1, 1 );
11507 push2.y = rng( -1, 1 );
11508 point ipos2( mpos + push2 );
11509 tripoint pos( ipos2, get_levz() );
11510 if( ( push2.x == 0 && push2.y == 0 ) || ( ( ipos2.x == u.posx() ) && ( ipos2.y == u.posy() ) ) ) {
11511 continue;
11512 }
11513 if( !critter_at( pos ) && other.can_move_to( pos ) ) {
11514 other.setpos( tripoint( ipos2, get_levz() ) );
11515 other.moves -= 50;
11516 std::string msg;
11517 if( one_in( creature_throw_resist ) ) {
11518 other.add_effect( effect_downed, 2_turns );
11519 msg = _( "The %1$s pushed the %2$s hard." );
11520 } else {
11521 msg = _( "The %1$s pushed the %2$s." );
11522 }
11523 add_msg( m_neutral, msg, critter.name(), other.name() );
11524 return;
11525 }
11526 }
11527 return;
11528 }
11529 }
11530}
void setx(int x)
Definition: character.h:847
void sety(int y)
Definition: character.h:850
bool is_throw_immune() const
Returns true if the player is immune to throws.
float get_dodge() const override
Definition: melee.cpp:782
int monstairz
Definition: game.h:1032
tripoint_range< tripoint > points_on_zlevel() const
Yields a range of all points that are contained in the map and have the z-level of this map (abs_sub)...
Definition: map.cpp:8411
bool can_move_to(const tripoint &p) const
Checks whether we can move to/through p.
Definition: monmove.cpp:249
int posy() const override
Definition: monster.h:498
void melee_attack(Creature &target)
Definition: monster.cpp:1370
int staircount
Definition: monster.h:509
void spawn(const tripoint &p)
Definition: monster.cpp:481
int posx() const override
Definition: monster.h:495
bool thrown_by_judo(monster *z)
Definition: monattack.cpp:4581
std::enable_if<!is_std_array< C >::value, constV & >::type random_entry_ref(const C &container)
Same as above, but with a statically allocated default value (using the default constructor).
Definition: rng.h:149

References _, Creature::add_effect(), add_msg(), monster::can_move_to(), coming_to_stairs, critter_at(), debugmsg, effect_downed, g, Character::get_dodge(), get_levz(), map::has_flag(), Character::has_trait(), map::has_zlevels(), is_empty(), Character::is_throw_immune(), m, m_neutral, m_warning, MAPSIZE_X, MAPSIZE_Y, monster::melee_attack(), monstairz, sounds::movement, Creature::moves, monster::name(), one_in(), other, place_critter_at(), point_north_west, map::points_on_zlevel(), Character::pos(), Character::posx(), monster::posx(), Character::posy(), monster::posy(), Character::posz(), monexamine::push(), random_entry_ref(), rl_dist(), rng(), Character::sees(), Character::setx(), Character::sety(), sounds::sound(), monster::spawn(), monster::staircount, string_format(), map::tername(), mattack::thrown_by_judo(), trait_LEG_TENT_BRACE, u, point::x, and point::y.

Referenced by do_turn(), and vertical_move().

◆ update_zombie_pos()

bool game::update_zombie_pos ( const monster critter,
const tripoint pos 
)

Redirects to the creature_tracker update_pos() function.

Definition at line 5017 of file game.cpp.

5018{
5019 return critter_tracker->update_pos( critter, pos );
5020}

References critter_tracker.

◆ use_computer()

void game::use_computer ( const tripoint p)

Checks to see if a player can use a computer (not illiterate, etc.) and uses if able.

Definition at line 4800 of file game.cpp.

4801{
4802 if( u.has_trait( trait_id( "ILLITERATE" ) ) ) {
4803 add_msg( m_info, _( "You can not read a computer screen!" ) );
4804 return;
4805 }
4806 if( u.is_blind() ) {
4807 // we don't have screen readers in game
4808 add_msg( m_info, _( "You can not see a computer screen!" ) );
4809 return;
4810 }
4811 if( u.has_trait( trait_id( "HYPEROPIC" ) ) && !u.worn_with_flag( "FIX_FARSIGHT" ) &&
4812 !u.has_effect( effect_contacts ) && !u.has_bionic( bionic_id( "bio_eye_optic" ) ) ) {
4813 add_msg( m_info, _( "You'll need to put on reading glasses before you can see the screen." ) );
4814 return;
4815 }
4816
4817 computer *used = m.computer_at( p );
4818
4819 if( used == nullptr ) {
4820 if( m.has_flag( "CONSOLE", p ) ) { //Console without map data
4821 add_msg( m_bad, _( "The console doesn't display anything coherent." ) );
4822 } else {
4823 debugmsg( "Tried to use computer at %s - none there", p.to_string() );
4824 }
4825 return;
4826 }
4827
4828 computer_session( *used ).use();
4829}
void use()
Handles player use of a computer.
computer * computer_at(const tripoint &p)
Definition: map.cpp:5534
static const efftype_id effect_contacts("contacts")

References _, add_msg(), map::computer_at(), debugmsg, effect_contacts, Character::has_bionic(), Creature::has_effect(), map::has_flag(), Character::has_trait(), Character::is_blind(), m, m_bad, m_info, tripoint::to_string(), u, computer_session::use(), and Character::worn_with_flag().

Referenced by examine().

◆ validate_camps()

void game::validate_camps ( )

validate camps to ensure they are on the overmap list

Definition at line 2034 of file game.cpp.

2035{
2036 basecamp camp = m.hoist_submap_camp( u.pos() );
2037 if( camp.is_valid() ) {
2038 overmap_buffer.add_camp( camp );
2040 } else if( camp.camp_omt_pos() != tripoint_abs_omt() ) {
2041 std::string camp_name = _( "Faction Camp" );
2042 camp.set_name( camp_name );
2043 overmap_buffer.add_camp( camp );
2045 }
2046}
bool is_valid() const
Definition: basecamp.h:125
void set_name(const std::string &new_name)
Definition: basecamp.cpp:575
tripoint_abs_omt camp_omt_pos() const
Definition: basecamp.h:134
basecamp hoist_submap_camp(const tripoint &p)
Definition: map.cpp:5565
void remove_submap_camp(const tripoint &)
Definition: map.cpp:5560
void add_camp(const basecamp &camp)
Add Basecamp to overmapbuffer.

References _, overmapbuffer::add_camp(), basecamp::camp_omt_pos(), map::hoist_submap_camp(), basecamp::is_valid(), m, overmap_buffer, Character::pos(), map::remove_submap_camp(), basecamp::set_name(), and u.

Referenced by load().

◆ validate_linked_vehicles()

void game::validate_linked_vehicles ( )

validate towed vehicles so they get linked up again after a load

Definition at line 1976 of file game.cpp.

1977{
1978 for( auto &veh : m.get_vehicles() ) {
1979 vehicle *v = veh.v;
1982 if( other_v ) {
1983 // the other vehicle is towing us.
1984 v->tow_data.set_towing( other_v, v );
1986 }
1987 }
1988 }
1989}
tripoint other_towing_point
Definition: vehicle.h:167
bool set_towing(vehicle *tower_veh, vehicle *towed_veh)
Definition: vehicle.cpp:5927
towing_data tow_data
Definition: vehicle.h:1887

References map::get_vehicles(), m, towing_data::other_towing_point, towing_data::set_towing(), vehicle::tow_data, tripoint_zero, map::veh_at(), and veh_pointer_or_null().

Referenced by load().

◆ validate_mounted_npcs()

void game::validate_mounted_npcs ( )

Definition at line 1991 of file game.cpp.

1992{
1993 for( monster &m : all_monsters() ) {
1994 if( m.has_effect( effect_ridden ) && m.mounted_player_id.is_valid() ) {
1995 player *mounted_pl = g->critter_by_id<player>( m.mounted_player_id );
1996 if( !mounted_pl ) {
1997 // Target no longer valid.
1998 m.mounted_player_id = character_id();
1999 m.remove_effect( effect_ridden );
2000 continue;
2001 }
2002 mounted_pl->mounted_creature = shared_from( m );
2003 mounted_pl->setpos( m.pos() );
2004 mounted_pl->add_effect( effect_riding, 1_turns, num_bp );
2005 m.mounted_player = mounted_pl;
2006 }
2007 }
2008}

References Creature::add_effect(), all_monsters(), character_id, effect_ridden, effect_riding, g, m, Character::mounted_creature, num_bp, Character::setpos(), and shared_from().

Referenced by load(), and vertical_shift().

◆ validate_npc_followers()

void game::validate_npc_followers ( )

validate list of followers to account for overmap buffers

Definition at line 2010 of file game.cpp.

2011{
2012 // Make sure visible followers are in the list.
2013 const std::vector<npc *> visible_followers = get_npcs_if( [&]( const npc & guy ) {
2014 return guy.is_player_ally();
2015 } );
2016 for( npc *guy : visible_followers ) {
2017 update_faction_api( guy );
2018 add_npc_follower( guy->getID() );
2019 }
2020 // Make sure overmapbuffered NPC followers are in the list.
2021 for( const auto &temp_guy : overmap_buffer.get_npcs_near_player( 300 ) ) {
2022 npc *guy = temp_guy.get();
2023 if( guy->is_player_ally() ) {
2024 update_faction_api( guy );
2025 add_npc_follower( guy->getID() );
2026 }
2027 }
2028 // Make sure that serialized player followers sync up with game list
2029 for( const auto &temp_id : u.follower_ids ) {
2030 add_npc_follower( temp_id );
2031 }
2032}
void add_npc_follower(const character_id &id)
Add follower id to set of followers.
Definition: game.cpp:1956
static void update_faction_api(npc *guy)
Definition: game.cpp:1968

References add_npc_follower(), player::follower_ids, get_npcs_if(), overmapbuffer::get_npcs_near_player(), Character::getID(), npc::is_player_ally(), overmap_buffer, u, and update_faction_api().

Referenced by load().

◆ vertical_move()

void game::vertical_move ( int  z,
bool  force,
bool  peeking = false 
)

Moves the player vertically.

If force == true then they are falling. If peeking == true, forbids some exotic movement options

Strength increases breath-holding capacity while diving Dexterity increases chance of moving past monsters on stairs Dodge increases chance of moving past monsters on stairs Strength increases chance of moving past monsters on stairs Melee increases chance of moving past monsters on stairs

Definition at line 10497 of file game.cpp.

10498{
10499 if( u.is_mounted() ) {
10500 auto mons = u.mounted_creature.get();
10501 if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
10502 if( !mons->check_mech_powered() ) {
10503 add_msg( m_bad, _( "Your %s refuses to move as its batteries have been drained." ),
10504 mons->get_name() );
10505 return;
10506 }
10507 }
10508 }
10509
10510 // > and < are used for diving underwater.
10511 if( m.has_flag( "SWIMMABLE", u.pos() ) && m.has_flag( TFLAG_DEEP_WATER, u.pos() ) ) {
10512 if( movez == -1 ) {
10513 if( u.is_underwater() ) {
10514 add_msg( m_info, _( "You are already underwater!" ) );
10515 return;
10516 }
10517 if( u.worn_with_flag( "FLOTATION" ) ) {
10518 add_msg( m_info, _( "You can't dive while wearing a flotation device." ) );
10519 return;
10520 }
10521 u.set_underwater( true );
10522 ///\EFFECT_STR increases breath-holding capacity while diving
10523 u.oxygen = 30 + 2 * u.str_cur;
10524 add_msg( _( "You dive underwater!" ) );
10525 } else {
10526 if( u.swim_speed() < 500 || u.shoe_type_count( itype_swim_fins ) ) {
10527 u.set_underwater( false );
10528 add_msg( _( "You surface." ) );
10529 } else {
10530 add_msg( m_info, _( "You try to surface but can't!" ) );
10531 }
10532 }
10533 u.moves -= 100;
10534 return;
10535 }
10536
10537 // Force means we're going down, even if there's no staircase, etc.
10538 bool climbing = false;
10539 int move_cost = 100;
10540 tripoint stairs( u.posx(), u.posy(), u.posz() + movez );
10541 if( m.has_zlevels() && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) {
10542 // Climbing
10543 if( m.has_floor_or_support( stairs ) ) {
10544 add_msg( m_info, _( "You can't climb here - there's a ceiling above your head." ) );
10545 return;
10546 }
10547
10548 std::vector<tripoint> pts;
10549 for( const auto &pt : m.points_in_radius( stairs, 1 ) ) {
10550 if( m.passable( pt ) &&
10551 m.has_floor_or_support( pt ) ) {
10552 pts.push_back( pt );
10553 }
10554 }
10555
10556 const int cost = u.climbing_cost( u.pos(), stairs );
10557
10558 if( cost == 0 ) {
10559 if( u.has_trait( trait_WEB_ROPE ) ) {
10560 if( pts.empty() ) {
10561 add_msg( m_info, _( "There is nothing above you that you can attach a web to." ) );
10562 } else if( can_use_mutation_warn( trait_WEB_ROPE, u ) ) {
10563 if( g->m.move_cost( u.pos() ) != 2 && g->m.move_cost( u.pos() ) != 3 ) {
10564 add_msg( m_info, _( "You can't spin a web rope there." ) );
10565 } else if( g->m.has_furn( u.pos() ) ) {
10566 add_msg( m_info, _( "There is already furniture at that location." ) );
10567 } else {
10568 if( query_yn( "Spin a rope and climb?" ) ) {
10569 add_msg( m_good, _( "You spin a rope of web." ) );
10570 g->m.furn_set( u.pos(), furn_str_id( "f_rope_up_web" ) );
10571 u.mod_moves( to_turns<int>( 2_seconds ) );
10573 vertical_move( movez, force, peeking );
10574 }
10575 }
10576 }
10577
10578 } else {
10579 add_msg( m_info, _( "You can't climb here - you need walls and/or furniture to brace against." ) );
10580
10581 }
10582 return;
10583
10584 }
10585
10586 if( cost <= 0 || pts.empty() ) {
10587 add_msg( m_info,
10588 _( "You can't climb here - there is no terrain above you that would support your weight." ) );
10589 return;
10590 } else {
10591 // TODO: Make it an extended action
10592 climbing = true;
10593 move_cost = cost;
10594
10596 if( !pnt ) {
10597 return;
10598 }
10599 stairs = *pnt;
10600 }
10601 }
10602
10603 if( !force && movez == -1 && !m.has_flag( "GOES_DOWN", u.pos() ) ) {
10604 add_msg( m_info, _( "You can't go down here!" ) );
10605 return;
10606 } else if( !climbing && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) {
10607 add_msg( m_info, _( "You can't go up here!" ) );
10608 return;
10609 }
10610
10611 if( force ) {
10612 // Let go of a grabbed cart.
10613 u.grab( OBJECT_NONE );
10614 } else if( u.grab_point != tripoint_zero ) {
10615 add_msg( m_info, _( "You can't drag things up and down stairs." ) );
10616 return;
10617 }
10618
10619 // Because get_levz takes z-value from the map, it will change when vertical_shift (m.has_zlevels() == true)
10620 // is called or when the map is loaded on new z-level (== false).
10621 // This caches the z-level we start the movement on (current) and the level we're want to end.
10622 const int z_before = get_levz();
10623 const int z_after = get_levz() + movez;
10624 if( z_after < -OVERMAP_DEPTH || z_after > OVERMAP_HEIGHT ) {
10625 debugmsg( "Tried to move outside allowed range of z-levels" );
10626 return;
10627 }
10628
10629 if( !u.move_effects( false ) ) {
10630 return;
10631 }
10632
10633 // Check if there are monsters are using the stairs.
10634 bool slippedpast = false;
10635 if( !m.has_zlevels() && !coming_to_stairs.empty() && !force ) {
10636 // TODO: Allow travel if zombie couldn't reach stairs, but spawn him when we go up.
10637 add_msg( m_warning, _( "You try to use the stairs. Suddenly you are blocked by a %s!" ),
10638 coming_to_stairs[0].name() );
10639 // Roll.
10640 ///\EFFECT_DEX increases chance of moving past monsters on stairs
10641
10642 ///\EFFECT_DODGE increases chance of moving past monsters on stairs
10643 int dexroll = dice( 6, u.dex_cur + u.get_skill_level( skill_dodge ) * 2 );
10644 ///\EFFECT_STR increases chance of moving past monsters on stairs
10645
10646 ///\EFFECT_MELEE increases chance of moving past monsters on stairs
10647 int strroll = dice( 3, u.str_cur + u.get_skill_level( skill_melee ) * 1.5 );
10648 if( coming_to_stairs.size() > 4 ) {
10649 add_msg( _( "The are a lot of them on the %s!" ), m.tername( u.pos() ) );
10650 dexroll /= 4;
10651 strroll /= 2;
10652 } else if( coming_to_stairs.size() > 1 ) {
10653 add_msg( m_warning, _( "There's something else behind it!" ) );
10654 dexroll /= 2;
10655 }
10656
10657 if( dexroll < 14 || strroll < 12 ) {
10659 u.moves -= 100;
10660 return;
10661 }
10662
10663 add_msg( _( "You manage to slip past!" ) );
10664 slippedpast = true;
10665 u.moves -= 100;
10666 }
10667
10668 // Shift the map up or down
10669
10670 std::unique_ptr<map> tmp_map_ptr;
10671 if( !m.has_zlevels() ) {
10672 tmp_map_ptr = std::make_unique<map>();
10673 }
10674
10675 map &maybetmp = m.has_zlevels() ? m : *( tmp_map_ptr.get() );
10676 if( m.has_zlevels() ) {
10677 // We no longer need to shift the map here! What joy
10678 } else {
10679 maybetmp.load( tripoint( get_levx(), get_levy(), z_after ), false );
10680 }
10681
10682 // Find the corresponding staircase
10683 bool rope_ladder = false;
10684 // TODO: Remove the stairfinding, make the mapgen gen aligned maps
10685 if( !force && !climbing ) {
10686 const cata::optional<tripoint> pnt = find_or_make_stairs( maybetmp, z_after, rope_ladder, peeking );
10687 if( !pnt ) {
10688 return;
10689 }
10690 stairs = *pnt;
10691 }
10692
10693 if( !force ) {
10694 monstairz = z_before;
10695 }
10696 // Save all monsters that can reach the stairs, remove them from the tracker,
10697 // then despawn the remaining monsters. Because it's a vertical shift, all
10698 // monsters are out of the bounds of the map and will despawn.
10699 shared_ptr_fast<monster> stored_mount;
10700 if( u.is_mounted() && !m.has_zlevels() ) {
10701 // Store a *copy* of the mount, so we can remove the original monster instance
10702 // from the tracker before the map shifts.
10703 // Map shifting would otherwise just despawn the mount and would later respawn it.
10704 stored_mount = make_shared_fast<monster>( *u.mounted_creature );
10706 }
10707 if( !m.has_zlevels() ) {
10708 const tripoint to = u.pos();
10709 for( monster &critter : all_monsters() ) {
10710 // if its a ladder instead of stairs - most zombies can't climb that.
10711 // unless that have a special flag to allow them to do so.
10712 if( ( m.has_flag( "DIFFICULT_Z", u.pos() ) && !critter.climbs() ) ||
10713 critter.has_effect( effect_ridden ) ||
10714 critter.has_effect( effect_tied ) ) {
10715 continue;
10716 }
10717 int turns = critter.turns_to_reach( to.xy() );
10718 if( turns < 10 && coming_to_stairs.size() < 8 && critter.will_reach( to.xy() )
10719 && !slippedpast ) {
10720 critter.staircount = 10 + turns;
10721 critter.on_unload();
10722 coming_to_stairs.push_back( critter );
10723 remove_zombie( critter );
10724 }
10725 }
10726 auto mons = critter_tracker->find( g->u.pos() );
10727 if( mons != nullptr ) {
10728 critter_tracker->remove( *mons );
10729 }
10730 shift_monsters( tripoint( 0, 0, movez ) );
10731 }
10732
10733 std::vector<shared_ptr_fast<npc>> npcs_to_bring;
10734 std::vector<monster *> monsters_following;
10735 if( !m.has_zlevels() && std::abs( movez ) == 1 ) {
10736 std::copy_if( active_npc.begin(), active_npc.end(), back_inserter( npcs_to_bring ),
10737 [this]( const shared_ptr_fast<npc> &np ) {
10738 return np->is_walking_with() && !np->is_mounted() && !np->in_sleep_state() &&
10739 rl_dist( np->pos(), u.pos() ) < 2;
10740 } );
10741 }
10742
10743 if( m.has_zlevels() && std::abs( movez ) == 1 ) {
10744 bool ladder = m.has_flag( "DIFFICULT_Z", u.pos() );
10745 for( monster &critter : all_monsters() ) {
10746 if( ladder && !critter.climbs() ) {
10747 continue;
10748 }
10749 if( critter.attack_target() == &g->u || ( !critter.has_effect( effect_ridden ) &&
10750 critter.has_effect( effect_pet ) && critter.friendly == -1 &&
10751 !critter.has_effect( effect_tied ) ) ) {
10752 monsters_following.push_back( &critter );
10753 }
10754 }
10755 }
10756
10757 if( u.is_mounted() ) {
10758 monster *crit = u.mounted_creature.get();
10759 if( crit->has_flag( MF_RIDEABLE_MECH ) ) {
10760 crit->use_mech_power( -1 );
10761 if( u.movement_mode_is( CMM_WALK ) ) {
10762 crit->use_mech_power( -2 );
10763 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
10764 crit->use_mech_power( -1 );
10765 } else if( u.movement_mode_is( CMM_RUN ) ) {
10766 crit->use_mech_power( -3 );
10767 }
10768 }
10769 } else {
10770 u.moves -= move_cost;
10771 }
10772 for( const auto &np : npcs_to_bring ) {
10773 if( np->in_vehicle ) {
10774 g->m.unboard_vehicle( np->pos() );
10775 }
10776 }
10777 const tripoint old_pos = g->u.pos();
10778 point submap_shift;
10779 vertical_shift( z_after );
10780 if( !force ) {
10781 submap_shift = update_map( stairs.x, stairs.y );
10782 }
10783
10784 // if an NPC or monster is on the stiars when player ascends/descends
10785 // they may end up merged on th esame tile, do some displacement to resolve that.
10786 // if, in the weird case of it not being possible to displace;
10787 // ( how did the player even manage to approach the stairs, if so? )
10788 // then nothing terrible happens, its just weird.
10789 if( critter_at<npc>( u.pos(), true ) || critter_at<monster>( u.pos(), true ) ) {
10790 std::string crit_name;
10791 bool player_displace = false;
10793 if( displace.has_value() ) {
10794 npc *guy = g->critter_at<npc>( u.pos(), true );
10795 if( guy ) {
10796 crit_name = guy->get_name();
10797 tripoint old_pos = guy->pos();
10798 if( !guy->is_enemy() ) {
10799 guy->move_away_from( u.pos(), true );
10800 if( old_pos != guy->pos() ) {
10801 add_msg( _( "%s moves out of the way for you." ), guy->get_name() );
10802 }
10803 } else {
10804 player_displace = true;
10805 }
10806 }
10807 monster *mon = g->critter_at<monster>( u.pos(), true );
10808 // if the monster is ridden by the player or an NPC:
10809 // Dont displace them. If they are mounted by a friendly NPC,
10810 // then the NPC will already have been displaced just above.
10811 // if they are ridden by the player, we want them to coexist on same tile
10812 if( mon && !mon->mounted_player ) {
10813 crit_name = mon->get_name();
10814 if( mon->friendly == -1 ) {
10815 mon->setpos( *displace );
10816 add_msg( _( "Your %s moves out of the way for you." ), mon->get_name() );
10817 } else {
10818 player_displace = true;
10819 }
10820 }
10821 if( player_displace ) {
10822 u.setpos( *displace );
10823 u.moves -= 20;
10824 add_msg( _( "You push past %s blocking the way." ), crit_name );
10825 }
10826 } else {
10827 debugmsg( "Failed to find a spot to displace into." );
10828 }
10829 }
10830
10831 // Now that we know the player's destination position, we can move their mount as well
10832 if( u.is_mounted() ) {
10833 if( stored_mount ) {
10834 assert( !m.has_zlevels() );
10835 stored_mount->spawn( g->u.pos() );
10836 if( critter_tracker->add( stored_mount ) ) {
10837 u.mounted_creature = stored_mount;
10838 }
10839 } else {
10840 u.mounted_creature->setpos( g->u.pos() );
10841 }
10842 }
10843
10844 if( !npcs_to_bring.empty() ) {
10845 // Would look nicer randomly scrambled
10846 std::vector<tripoint> candidates = closest_points_first( u.pos(), 1 );
10847 candidates.erase( std::remove_if( candidates.begin(), candidates.end(),
10848 [this]( const tripoint & c ) {
10849 return !is_empty( c );
10850 } ), candidates.end() );
10851
10852 for( const auto &np : npcs_to_bring ) {
10853 const auto found = std::find_if( candidates.begin(), candidates.end(),
10854 [this, np]( const tripoint & c ) {
10855 return !np->is_dangerous_fields( m.field_at( c ) ) && m.tr_at( c ).is_benign();
10856 } );
10857 if( found != candidates.end() ) {
10858 // TODO: De-uglify
10859 np->setpos( *found );
10860 np->place_on_map();
10861 np->setpos( *found );
10862 candidates.erase( found );
10863 }
10864
10865 if( candidates.empty() ) {
10866 break;
10867 }
10868 }
10869
10870 reload_npcs();
10871 }
10872
10873 // This ugly check is here because of stair teleport bullshit
10874 // TODO: Remove stair teleport bullshit
10875 if( rl_dist( g->u.pos(), old_pos ) <= 1 ) {
10876 for( monster *m : monsters_following ) {
10877 m->set_dest( g->u.pos() );
10878 }
10879 }
10880
10881 if( rope_ladder ) {
10882 m.ter_set( u.pos(), t_rope_up );
10883 }
10884
10885 if( m.ter( stairs ) == t_manhole_cover ) {
10886 m.spawn_item( stairs + point( rng( -1, 1 ), rng( -1, 1 ) ), itype_manhole_cover );
10887 m.ter_set( stairs, t_manhole );
10888 }
10889
10890 // Wouldn't work and may do strange things
10891 if( u.is_hauling() && !m.has_zlevels() ) {
10892 add_msg( _( "You cannot haul items here." ) );
10893 u.stop_hauling();
10894 }
10895
10896 if( u.is_hauling() ) {
10897 const tripoint adjusted_pos = old_pos - sm_to_ms_copy( submap_shift );
10898 start_hauling( adjusted_pos );
10899 }
10900
10901 m.invalidate_map_cache( g->get_levz() );
10902 // Upon force movement, traps can not be avoided.
10903 m.creature_on_trap( u, !force );
10904
10906}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
@ CMM_WALK
Definition: character.h:97
@ CMM_CROUCH
Definition: character.h:99
bool move_effects(bool attacking) override
Processes effects which may prevent the Character from moving (bear traps, crushed,...
Definition: character.cpp:1519
int swim_speed() const
Returns the player's speed for swimming across water tiles.
Definition: character.cpp:868
int oxygen
Definition: character.h:1588
void mutation_spend_resources(const trait_id &mut)
Removes the appropriate costs (NOTE: will reapply mods & recalc sightlines in case of newly activated...
Definition: mutation.cpp:1723
int shoe_type_count(const itype_id &it) const
Returns 1 if the player is wearing an item of that count on one foot, 2 if on both,...
Definition: character.cpp:8779
std::string get_name() const override
Definition: character.cpp:5967
void start_hauling(const tripoint &pos)
Definition: game.cpp:10908
cata::optional< tripoint > find_or_make_stairs(map &mp, int z_after, bool &rope_ladder, bool peeking)
Returns the other end of the stairs (if any).
Definition: game.cpp:10943
bool use_mech_power(int amt)
Definition: monster.cpp:2368
Character * mounted_player
Definition: monster.h:458
int climbing_cost(const tripoint &from, const tripoint &to) const
Checks both the neighborhoods of from and to for climbable surfaces, returns move cost of climbing fr...
Definition: player.cpp:4373
void set_underwater(bool)
Definition: player.cpp:588
static const efftype_id effect_tied("tied")
static const itype_id itype_manhole_cover("manhole_cover")
static const skill_id skill_melee("melee")
static cata::optional< tripoint > point_selection_menu(const std::vector< tripoint > &pts)
Definition: game.cpp:10448
static const itype_id itype_swim_fins("swim_fins")
static const trait_id trait_WEB_ROPE("WEB_ROPE")
ter_id t_rope_up
Definition: mapdata.cpp:719
ter_id t_manhole
Definition: mapdata.cpp:718
bool can_use_mutation_warn(const trait_id &mut, const Character &character)
Calls can_use_mutation and if it fails, print a standard message.
Definition: mutation.cpp:1712
void avatar_moves(const avatar &u, const map &m, const tripoint &p)
Definition: game.cpp:12565
int ladder(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:9445
point displace(type dir, int dist=1)
Returns point(0, 0) displaced in specified direction by a specified distance.
Definition: overmap.cpp:4085

References _, active_npc, add_msg(), all_monsters(), cata_event_dispatch::avatar_moves(), c, can_use_mutation_warn(), player::climbing_cost(), closest_points_first(), CMM_CROUCH, CMM_RUN, CMM_WALK, coming_to_stairs, map::creature_on_trap(), critter_tracker, debugmsg, Character::dex_cur, dice(), om_direction::displace(), effect_pet, effect_ridden, effect_tied, find_empty_spot_nearby(), find_or_make_stairs(), monster::friendly, g, get_levx(), get_levy(), get_levz(), Character::get_name(), monster::get_name(), Character::get_skill_level(), avatar::grab(), player::grab_point, map::has_flag(), monster::has_flag(), map::has_floor_or_support(), Character::has_trait(), map::has_zlevels(), map::invalidate_map_cache(), npc::is_enemy(), Character::is_hauling(), Character::is_mounted(), Creature::is_underwater(), itype_manhole_cover, itype_swim_fins, iuse::ladder(), map::load(), m, m_bad, m_good, m_info, m_warning, MF_RIDEABLE_MECH, Creature::mod_moves(), monstairz, Character::mounted_creature, monster::mounted_player, npc::move_away_from(), move_cost(), Character::move_effects(), Character::movement_mode_is(), Creature::moves, Character::mutation_spend_resources(), om_direction::name(), OBJECT_NONE, OVERMAP_HEIGHT, Character::oxygen, map::passable(), point_selection_menu(), map::points_in_radius(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), query_yn(), reload_npcs(), remove_zombie(), rl_dist(), rng(), player::set_underwater(), Character::setpos(), monster::setpos(), shift_monsters(), Character::shoe_type_count(), skill_dodge, skill_melee, sm_to_ms_copy(), map::spawn_item(), start_hauling(), Character::stop_hauling(), Character::str_cur, Character::swim_speed(), t_manhole, t_manhole_cover, t_rope_up, map::ter(), map::ter_set(), map::tername(), TFLAG_DEEP_WATER, trait_WEB_ROPE, tripoint_zero, u, update_map(), update_stair_monsters(), monster::use_mech_power(), vertical_move(), vertical_shift(), Character::worn_with_flag(), tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by handle_action(), peek(), and vertical_move().

◆ vertical_notes()

void game::vertical_notes ( int  z_before,
int  z_after 
)

Add goes up/down auto_notes (if turned on)

Definition at line 11130 of file game.cpp.

11131{
11132 if( z_before == z_after || !get_option<bool>( "AUTO_NOTES" ) ||
11133 !get_option<bool>( "AUTO_NOTES_STAIRS" ) ) {
11134 return;
11135 }
11136
11137 if( !m.inbounds_z( z_before ) || !m.inbounds_z( z_after ) ) {
11138 debugmsg( "game::vertical_notes invalid arguments: z_before == %d, z_after == %d",
11139 z_before, z_after );
11140 return;
11141 }
11142 // Figure out where we know there are up/down connectors
11143 // Fill in all the tiles we know about (e.g. subway stations)
11144 static const int REVEAL_RADIUS = 40;
11145 for( const tripoint_abs_omt &p : points_in_radius( u.global_omt_location(), REVEAL_RADIUS ) ) {
11146 const tripoint_abs_omt cursp_before( p.xy(), z_before );
11147 const tripoint_abs_omt cursp_after( p.xy(), z_after );
11148
11149 if( !overmap_buffer.seen( cursp_before ) ) {
11150 continue;
11151 }
11152 if( overmap_buffer.has_note( cursp_after ) ) {
11153 // Already has a note -> never add an AUTO-note
11154 continue;
11155 }
11156 const oter_id &ter = overmap_buffer.ter( cursp_before );
11157 const oter_id &ter2 = overmap_buffer.ter( cursp_after );
11158 if( z_after > z_before && ter->has_flag( known_up ) &&
11159 !ter2->has_flag( known_down ) ) {
11160 overmap_buffer.set_seen( cursp_after, true );
11161 overmap_buffer.add_note( cursp_after, string_format( ">:W;%s", _( "AUTO: goes down" ) ) );
11162 } else if( z_after < z_before && ter->has_flag( known_down ) &&
11163 !ter2->has_flag( known_up ) ) {
11164 overmap_buffer.set_seen( cursp_after, true );
11165 overmap_buffer.add_note( cursp_after, string_format( "<:W;%s", _( "AUTO: goes up" ) ) );
11166 }
11167 }
11168}
bool inbounds_z(const int z) const
Definition: map.h:1645
void add_note(const tripoint_abs_omt &, const std::string &message)
@ known_up
Definition: omdata.h:161
@ known_down
Definition: omdata.h:160
bool has_flag(oter_flags flag) const
Definition: omdata.h:332

References _, overmapbuffer::add_note(), debugmsg, Character::global_omt_location(), oter_t::has_flag(), overmapbuffer::has_note(), map::inbounds_z(), known_down, known_up, m, overmap_buffer, points_in_radius(), overmapbuffer::seen(), overmapbuffer::set_seen(), string_format(), overmapbuffer::ter(), and u.

Referenced by vertical_shift().

◆ vertical_shift()

void game::vertical_shift ( int  z_after)

Actual z-level movement part of vertical_move.

Doesn't include stair finding, traps etc.

Definition at line 11093 of file game.cpp.

11094{
11095 if( z_after < -OVERMAP_DEPTH || z_after > OVERMAP_HEIGHT ) {
11096 debugmsg( "Tried to get z-level %d outside allowed range of %d-%d",
11097 z_after, -OVERMAP_DEPTH, OVERMAP_HEIGHT );
11098 return;
11099 }
11100
11101 // TODO: Implement dragging stuff up/down
11102 u.grab( OBJECT_NONE );
11103
11104 scent.reset();
11105
11106 u.setz( z_after );
11107 const int z_before = get_levz();
11108 if( !m.has_zlevels() ) {
11109 m.clear_vehicle_cache( z_before );
11110 m.access_cache( z_before ).vehicle_list.clear();
11111 m.access_cache( z_before ).zone_vehicles.clear();
11112 m.access_cache( z_before ).map_memory_seen_cache.reset();
11113 m.set_transparency_cache_dirty( z_before );
11114 m.set_outside_cache_dirty( z_before );
11115 m.load( tripoint( get_levx(), get_levy(), z_after ), true );
11116 shift_monsters( tripoint( 0, 0, z_after - z_before ) );
11117 reload_npcs();
11118 } else {
11119 // Shift the map itself
11120 m.vertical_shift( z_after );
11121 }
11122
11123 m.spawn_monsters( true );
11124 // this may be required after a vertical shift if z-levels are not enabled
11125 // the critter is unloaded/loaded, and it needs to reconstruct its rider data after being reloaded.
11127 vertical_notes( z_before, z_after );
11128}
void setz(int z)
Definition: character.h:853
void vertical_notes(int z_before, int z_after)
Add goes up/down auto_notes (if turned on)
Definition: game.cpp:11130
void set_transparency_cache_dirty(const int zlev)
Sets a dirty flag on the a given cache.
Definition: map.h:393
void set_outside_cache_dirty(const int zlev)
Definition: map.h:430
void vertical_shift(int newz)
Moves the map vertically to (not by!) newz.
Definition: map.cpp:6736
std::set< vehicle * > zone_vehicles
Definition: map.h:346
std::set< vehicle * > vehicle_list
Definition: map.h:345

References map::access_cache(), map::clear_vehicle_cache(), debugmsg, get_levx(), get_levy(), get_levz(), avatar::grab(), map::has_zlevels(), map::load(), m, level_cache::map_memory_seen_cache, OBJECT_NONE, OVERMAP_DEPTH, OVERMAP_HEIGHT, reload_npcs(), scent_map::reset(), scent, map::set_outside_cache_dirty(), map::set_transparency_cache_dirty(), Character::setz(), shift_monsters(), map::spawn_monsters(), u, validate_mounted_npcs(), level_cache::vehicle_list, vertical_notes(), map::vertical_shift(), and level_cache::zone_vehicles.

Referenced by place_player(), and vertical_move().

◆ walk_move()

bool game::walk_move ( const tripoint dest,
bool  via_ramp = false 
)

TODO: This should really use the mounted creatures stamina, if mounted. Monsters don't currently have stamina however. For the time being just don't burn players stamina when mounted.

Dexterity decreases chance of tentacles getting stuck to the ground Intelligence decreases chance of tentacles getting stuck to the ground

Definition at line 9312 of file game.cpp.

9313{
9314 if( m.has_flag_ter( TFLAG_SMALL_PASSAGE, dest_loc ) ) {
9315 if( u.get_size() > MS_MEDIUM ) {
9316 add_msg( m_warning, _( "You can't fit there." ) );
9317 return false; // character too large to fit through a tight passage
9318 }
9319 if( u.is_mounted() ) {
9320 monster *mount = u.mounted_creature.get();
9321 if( mount->get_size() > MS_MEDIUM ) {
9322 add_msg( m_warning, _( "Your mount can't fit there." ) );
9323 return false; // char's mount is too large for tight passages
9324 }
9325 }
9326 }
9327
9328 if( u.is_mounted() ) {
9329 auto mons = u.mounted_creature.get();
9330 if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
9331 if( !mons->check_mech_powered() ) {
9332 add_msg( m_bad, _( "Your %s refuses to move as its batteries have been drained." ),
9333 mons->get_name() );
9334 return false;
9335 }
9336 }
9337 if( !mons->move_effects( false ) ) {
9338 add_msg( m_bad, _( "You cannot move as your %s isn't able to move." ), mons->get_name() );
9339 return false;
9340 }
9341 }
9342 const optional_vpart_position vp_here = m.veh_at( u.pos() );
9343 const optional_vpart_position vp_there = m.veh_at( dest_loc );
9344
9345 bool pushing = false; // moving -into- grabbed tile; skip check for move_cost > 0
9346 bool pulling = false; // moving -away- from grabbed tile; check for move_cost > 0
9347 bool shifting_furniture = false; // moving furniture and staying still; skip check for move_cost > 0
9348
9349 const tripoint furn_pos = u.pos() + u.grab_point;
9350 const tripoint furn_dest = dest_loc + u.grab_point;
9351
9352 bool grabbed = u.get_grab_type() != OBJECT_NONE;
9353 if( grabbed ) {
9354 const tripoint dp = dest_loc - u.pos();
9355 pushing = dp == u.grab_point;
9356 pulling = dp == -u.grab_point;
9357 }
9358 if( grabbed && dest_loc.z != u.posz() ) {
9359 add_msg( m_warning, _( "You let go of the grabbed object." ) );
9360 grabbed = false;
9361 u.grab( OBJECT_NONE );
9362 }
9363
9364 // Now make sure we're actually holding something
9365 const vehicle *grabbed_vehicle = nullptr;
9366 if( grabbed && u.get_grab_type() == OBJECT_FURNITURE ) {
9367 // We only care about shifting, because it's the only one that can change our destination
9368 if( m.has_furn( u.pos() + u.grab_point ) ) {
9369 shifting_furniture = !pushing && !pulling;
9370 } else {
9371 // We were grabbing a furniture that isn't there
9372 grabbed = false;
9373 }
9374 } else if( grabbed && u.get_grab_type() == OBJECT_VEHICLE ) {
9375 grabbed_vehicle = veh_pointer_or_null( m.veh_at( u.pos() + u.grab_point ) );
9376 if( grabbed_vehicle == nullptr ) {
9377 // We were grabbing a vehicle that isn't there anymore
9378 grabbed = false;
9379 }
9380 } else if( grabbed ) {
9381 // We were grabbing something WEIRD, let's pretend we weren't
9382 grabbed = false;
9383 }
9384 if( u.grab_point != tripoint_zero && !grabbed ) {
9385 add_msg( m_warning, _( "Can't find grabbed object." ) );
9386 u.grab( OBJECT_NONE );
9387 }
9388
9389 if( m.impassable( dest_loc ) && !pushing && !shifting_furniture ) {
9390 if( vp_there && u.mounted_creature && u.mounted_creature->has_flag( MF_RIDEABLE_MECH ) &&
9391 vp_there->vehicle().handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
9392 tripoint diff = dest_loc - u.pos();
9393 if( diff.x < 0 ) {
9394 diff.x -= 2;
9395 } else if( diff.x > 0 ) {
9396 diff.x += 2;
9397 }
9398 if( diff.y < 0 ) {
9399 diff.y -= 2;
9400 } else if( diff.y > 0 ) {
9401 diff.y += 2;
9402 }
9403 u.mounted_creature->shove_vehicle( dest_loc + diff.xy(),
9404 dest_loc );
9405 }
9406 return false;
9407 }
9408 if( vp_there && !vp_there->vehicle().handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
9409 return false;
9410 }
9411 if( u.is_mounted() && !pushing && vp_there ) {
9412 add_msg( m_warning, _( "You cannot board a vehicle whilst riding." ) );
9413 return false;
9414 }
9415 u.set_underwater( false );
9416
9417 if( !shifting_furniture && !pushing && is_dangerous_tile( dest_loc ) ) {
9418 std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );
9419 if( get_option<std::string>( "DANGEROUS_TERRAIN_WARNING_PROMPT" ) == "ALWAYS" &&
9420 !prompt_dangerous_tile( dest_loc ) ) {
9421 return true;
9422 } else if( get_option<std::string>( "DANGEROUS_TERRAIN_WARNING_PROMPT" ) == "RUNNING" &&
9423 ( !u.movement_mode_is( CMM_RUN ) || !prompt_dangerous_tile( dest_loc ) ) ) {
9425 _( "Stepping into that %1$s looks risky. Run into it if you wish to enter anyway." ),
9426 enumerate_as_string( harmful_stuff ) );
9427 return true;
9428 } else if( get_option<std::string>( "DANGEROUS_TERRAIN_WARNING_PROMPT" ) == "CROUCHING" &&
9429 ( !u.movement_mode_is( CMM_CROUCH ) || !prompt_dangerous_tile( dest_loc ) ) ) {
9431 _( "Stepping into that %1$s looks risky. Crouch and move into it if you wish to enter anyway." ),
9432 enumerate_as_string( harmful_stuff ) );
9433 return true;
9434 } else if( get_option<std::string>( "DANGEROUS_TERRAIN_WARNING_PROMPT" ) == "NEVER" &&
9435 !u.movement_mode_is( CMM_RUN ) ) {
9437 _( "Stepping into that %1$s looks risky. Run into it if you wish to enter anyway." ),
9438 enumerate_as_string( harmful_stuff ) );
9439 return true;
9440 }
9441 }
9442 // Used to decide whether to print a 'moving is slow message
9443 const int mcost_from = m.move_cost( u.pos() ); //calculate this _before_ calling grabbed_move
9444
9445 int modifier = 0;
9446 if( grabbed && u.get_grab_type() == OBJECT_FURNITURE && u.pos() + u.grab_point == dest_loc ) {
9447 modifier = -m.furn( dest_loc ).obj().movecost;
9448 }
9449
9450 int multiplier = 1;
9451 if( u.is_on_ground() ) {
9452 multiplier *= 3;
9453 }
9454
9455 const int mcost = m.combined_movecost( u.pos(), dest_loc, grabbed_vehicle, modifier,
9456 via_ramp ) * multiplier;
9457 if( grabbed_move( dest_loc - u.pos() ) ) {
9458 return true;
9459 } else if( mcost == 0 ) {
9460 return false;
9461 }
9462 bool diag = trigdist && u.posx() != dest_loc.x && u.posy() != dest_loc.y;
9463 const int previous_moves = u.moves;
9464 if( u.is_mounted() ) {
9465 auto crit = u.mounted_creature.get();
9466 if( !crit->has_flag( MF_RIDEABLE_MECH ) &&
9467 ( m.has_flag_ter_or_furn( "MOUNTABLE", dest_loc ) ||
9468 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR", dest_loc ) ||
9469 m.has_flag_ter_or_furn( "OPENCLOSE_INSIDE", dest_loc ) ||
9470 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR_DAMAGED", dest_loc ) ||
9471 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR_REINFORCED", dest_loc ) ) ) {
9472 add_msg( m_warning, _( "You cannot pass obstacles whilst mounted." ) );
9473 return false;
9474 }
9475 const double base_moves = u.run_cost( mcost, diag ) * 100.0 / crit->get_speed();
9476 const double encumb_moves = u.get_weight() / 4800.0_gram;
9477 u.moves -= static_cast<int>( std::ceil( base_moves + encumb_moves ) );
9478 if( u.movement_mode_is( CMM_WALK ) ) {
9479 crit->use_mech_power( -2 );
9480 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
9481 crit->use_mech_power( -1 );
9482 } else if( u.movement_mode_is( CMM_RUN ) ) {
9483 crit->use_mech_power( -3 );
9484 }
9485 } else {
9486 u.moves -= u.run_cost( mcost, diag );
9487 /**
9488 TODO:
9489 This should really use the mounted creatures stamina, if mounted.
9490 Monsters don't currently have stamina however.
9491 For the time being just don't burn players stamina when mounted.
9492 */
9493 if( grabbed_vehicle == nullptr || grabbed_vehicle->wheelcache.empty() ) {
9494 //Burn normal amount of stamina if no vehicle grabbed or vehicle lacks wheels
9495 u.burn_move_stamina( previous_moves - u.moves );
9496 } else {
9497 //Burn half as much stamina if vehicle has wheels, without changing move time
9498 u.burn_move_stamina( 0.50 * ( previous_moves - u.moves ) );
9499 }
9500 }
9501 // Max out recoil & reset aim point
9504
9505 // Print a message if movement is slow
9506 const int mcost_to = m.move_cost( dest_loc ); //calculate this _after_ calling grabbed_move
9507 const bool fungus = m.has_flag_ter_or_furn( "FUNGUS", u.pos() ) ||
9508 m.has_flag_ter_or_furn( "FUNGUS",
9509 dest_loc ); //fungal furniture has no slowing effect on mycus characters
9510 const bool slowed = ( ( !u.has_trait( trait_PARKOUR ) && ( mcost_to > 2 || mcost_from > 2 ) ) ||
9511 mcost_to > 4 || mcost_from > 4 ) &&
9512 !( u.has_trait( trait_M_IMMUNE ) && fungus );
9513 if( slowed && !u.is_mounted() ) {
9514 // Unless u.pos() has a higher movecost than dest_loc, state that dest_loc is the cause
9515 if( mcost_to >= mcost_from ) {
9516 if( auto displayed_part = vp_there.part_displayed() ) {
9517 add_msg( m_warning, _( "Moving onto this %s is slow!" ),
9518 displayed_part->part().name() );
9519 sfx::do_obstacle( displayed_part->part().info().get_id().str() );
9520 } else {
9521 add_msg( m_warning, _( "Moving onto this %s is slow!" ), m.name( dest_loc ) );
9522 sfx::do_obstacle( m.ter( dest_loc ).id().str() );
9523 }
9524 } else {
9525 if( auto displayed_part = vp_here.part_displayed() ) {
9526 add_msg( m_warning, _( "Moving off of this %s is slow!" ),
9527 displayed_part->part().name() );
9528 sfx::do_obstacle( displayed_part->part().info().get_id().str() );
9529 } else {
9530 add_msg( m_warning, _( "Moving off of this %s is slow!" ), m.name( u.pos() ) );
9531 sfx::do_obstacle( m.ter( u.pos() ).id().str() );
9532 }
9533 }
9534 }
9535 if( !u.is_mounted() && u.has_trait( trait_id( "LEG_TENT_BRACE" ) ) &&
9536 ( !u.footwear_factor() ||
9537 ( u.footwear_factor() == .5 && one_in( 2 ) ) ) ) {
9538 // DX and IN are long suits for Cephalopods,
9539 // so this shouldn't cause too much hardship
9540 // Presumed that if it's swimmable, they're
9541 // swimming and won't stick
9542 ///\EFFECT_DEX decreases chance of tentacles getting stuck to the ground
9543
9544 ///\EFFECT_INT decreases chance of tentacles getting stuck to the ground
9545 if( !m.has_flag( "SWIMMABLE", dest_loc ) && one_in( 80 + u.dex_cur + u.int_cur ) ) {
9546 add_msg( _( "Your tentacles stick to the ground, but you pull them free." ) );
9547 u.mod_fatigue( 1 );
9548 }
9549 }
9550 if( !u.has_artifact_with( AEP_STEALTH ) && !u.has_trait( trait_id( "DEBUG_SILENT" ) ) ) {
9551 int volume = u.is_stealthy() ? 3 : 6;
9552 volume *= u.mutation_value( "noise_modifier" );
9553 if( volume > 0 ) {
9555 volume = 2;
9556 } else if( u.has_bionic( bionic_id( "bio_ankles" ) ) ) {
9557 volume = 12;
9558 }
9559 if( u.movement_mode_is( CMM_RUN ) ) {
9560 volume *= 1.5;
9561 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
9562 volume /= 2;
9563 }
9564 if( u.is_mounted() ) {
9565 auto mons = u.mounted_creature.get();
9566 switch( mons->get_size() ) {
9567 case MS_TINY:
9568 volume = 0; // No sound for the tinies
9569 break;
9570 case MS_SMALL:
9571 volume /= 3;
9572 break;
9573 case MS_MEDIUM:
9574 break;
9575 case MS_LARGE:
9576 volume *= 1.5;
9577 break;
9578 case MS_HUGE:
9579 volume *= 2;
9580 break;
9581 default:
9582 break;
9583 }
9584 if( mons->has_flag( MF_LOUDMOVES ) ) {
9585 volume += 6;
9586 }
9587 sounds::sound( dest_loc, volume, sounds::sound_t::movement, mons->type->get_footsteps(), false,
9588 "none", "none" );
9589 } else {
9590 sounds::sound( dest_loc, volume, sounds::sound_t::movement, _( "footsteps" ), true,
9591 "none", "none" ); // Sound of footsteps may awaken nearby monsters
9592 }
9594 }
9595
9596 if( one_in( 20 ) && u.has_artifact_with( AEP_MOVEMENT_NOISE ) ) {
9597 sounds::sound( u.pos(), 40, sounds::sound_t::movement, _( "a rattling sound." ), true,
9598 "misc", "rattling" );
9599 }
9600 }
9601
9602 if( m.has_flag_ter_or_furn( TFLAG_HIDE_PLACE, dest_loc ) ) {
9603 add_msg( m_good, _( "You are hiding in the %s." ), m.name( dest_loc ) );
9604 }
9605
9606 if( dest_loc != u.pos() ) {
9608 }
9609
9610 tripoint oldpos = u.pos();
9611 point submap_shift = place_player( dest_loc );
9612 point ms_shift = sm_to_ms_copy( submap_shift );
9613 oldpos = oldpos - ms_shift;
9614
9615 if( pulling ) {
9616 const tripoint shifted_furn_pos = furn_pos - ms_shift;
9617 const tripoint shifted_furn_dest = furn_dest - ms_shift;
9618 const time_duration fire_age = m.get_field_age( shifted_furn_pos, fd_fire );
9619 const int fire_intensity = m.get_field_intensity( shifted_furn_pos, fd_fire );
9620 m.remove_field( shifted_furn_pos, fd_fire );
9621 m.set_field_intensity( shifted_furn_dest, fd_fire, fire_intensity );
9622 m.set_field_age( shifted_furn_dest, fd_fire, fire_age );
9623 }
9624
9625 if( u.is_hauling() ) {
9626 start_hauling( oldpos );
9627 }
9628
9630
9631 return true;
9632}
void burn_move_stamina(int moves)
Definition: character.cpp:7094
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3099
units::mass get_weight() const override
Returns body weight plus weight of inventory and worn/wielded items.
Definition: character.cpp:3533
bool is_on_ground() const override
Returns true if the player is knocked over or has broken legs.
Definition: character.cpp:948
bool is_wearing(const itype_id &it) const
Returns true if the player is wearing the item.
Definition: character.cpp:3119
float mutation_value(const std::string &val) const
Goes over all mutations, gets min and max of a value with given name.
Definition: character.cpp:6622
int run_cost(int base_cost, bool diag=false) const
Returns the player's modified base movement cost.
Definition: character.cpp:9814
m_size get_size() const override
Get size class of character.
Definition: character.cpp:529
bool grabbed_move(const tripoint &dp)
Check for dangerous stuff at dest_loc, return false if the player decides not to step there.
Definition: game.cpp:10237
bool is_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:9241
const string_id< T > & id() const
Definition: ammo_effect.cpp:33
int combined_movecost(const tripoint &from, const tripoint &to, const vehicle *ignored_vehicle=nullptr, int modifier=0, bool flying=false, bool via_ramp=false) const
Cost to move out of one tile and into the next.
Definition: map.cpp:1849
m_size get_size() const override
Definition: monster.cpp:2668
cata::optional< vpart_reference > part_displayed() const
Definition: vehicle.cpp:2496
bool is_stealthy() const
Returns true if the player has stealthy movement.
cata::optional< tripoint > last_target_pos
Definition: player.h:690
@ MS_TINY
Definition: creature.h:58
@ MS_LARGE
Definition: creature.h:61
@ MS_MEDIUM
Definition: creature.h:60
static const itype_id itype_rm13_armor_on("rm13_armor_on")
static const trait_id trait_M_IMMUNE("M_IMMUNE")
@ TFLAG_SMALL_PASSAGE
Definition: mapdata.h:320
@ TFLAG_HIDE_PLACE
Definition: mapdata.h:315
@ MF_LOUDMOVES
Definition: mtype.h:175
void fungus(player &p, const tripoint &examp)
Remove furniture.
Definition: iexamine.cpp:2122
void do_obstacle(const std::string &obst="")
Definition: sounds.cpp:1626
void do_footstep()
Definition: sounds.cpp:1603

References _, add_msg(), AEP_MOVEMENT_NOISE, AEP_STEALTH, cata_event_dispatch::avatar_moves(), Character::burn_move_stamina(), CMM_CROUCH, CMM_RUN, CMM_WALK, map::combined_movecost(), Character::dex_cur, sfx::do_footstep(), sfx::do_obstacle(), enumerate_as_string(), fd_fire, Character::footwear_factor(), iexamine::fungus(), map::furn(), get_dangerous_tile(), map::get_field_age(), map::get_field_intensity(), avatar::get_grab_type(), Character::get_size(), monster::get_size(), Character::get_weight(), avatar::grab(), player::grab_point, grabbed_move(), Character::has_artifact_with(), Character::has_bionic(), map::has_flag(), map::has_flag_ter(), map::has_flag_ter_or_furn(), map::has_furn(), Character::has_trait(), int_id< T >::id(), map::impassable(), Character::int_cur, is_dangerous_tile(), Character::is_hauling(), Character::is_mounted(), Character::is_on_ground(), player::is_stealthy(), Character::is_wearing(), itype_rm13_armor_on, player::last_target_pos, m, m_bad, m_good, m_warning, MAX_RECOIL, MF_LOUDMOVES, MF_RIDEABLE_MECH, Character::mod_fatigue(), Character::mounted_creature, map::move_cost(), map_data_common_t::movecost, sounds::movement, Character::movement_mode_is(), Creature::moves, MS_HUGE, MS_LARGE, MS_MEDIUM, MS_SMALL, MS_TINY, Character::mutation_value(), map::name(), cata::nullopt, int_id< T >::obj(), OBJECT_FURNITURE, OBJECT_NONE, OBJECT_VEHICLE, on_move_effects(), one_in(), optional_vpart_position::part_displayed(), place_player(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), prompt_dangerous_tile(), Character::recoil, map::remove_field(), Character::run_cost(), map::set_field_age(), map::set_field_intensity(), player::set_underwater(), sm_to_ms_copy(), sounds::sound(), start_hauling(), string_id< T >::str(), map::ter(), TFLAG_HIDE_PLACE, TFLAG_SMALL_PASSAGE, trait_M_IMMUNE, trait_PARKOUR, trigdist, tripoint_zero, u, map::veh_at(), veh_pointer_or_null(), vehicle::wheelcache, tripoint::x, tripoint::xy(), tripoint::y, and tripoint::z.

◆ wield() [1/2]

void game::wield ( )
private

Definition at line 9101 of file game.cpp.

9102{
9104
9105 if( loc ) {
9106 wield( loc );
9107 } else {
9108 add_msg( _( "Never mind." ) );
9109 }
9110}
item_location wield(avatar &you)
Item wielding/unwielding menu.

References _, add_msg(), u, wield(), and game_menus::inv::wield().

Referenced by handle_action(), inventory_item_menu(), and wield().

◆ wield() [2/2]

void game::wield ( item_location loc)
private

Definition at line 9013 of file game.cpp.

9014{
9015 if( u.is_armed() ) {
9016 const bool is_unwielding = u.is_wielding( *loc );
9017 const auto ret = u.can_unwield( *loc );
9018
9019 if( !ret.success() ) {
9020 add_msg( m_info, "%s", ret.c_str() );
9021 }
9022
9023 u.unwield();
9024
9025 if( is_unwielding ) {
9026 if( !u.martial_arts_data->selected_is_none() ) {
9027 u.martial_arts_data->martialart_use_message( u );
9028 }
9029 return;
9030 }
9031 }
9032
9033 const auto ret = u.can_wield( *loc );
9034 if( !ret.success() ) {
9035 add_msg( m_info, "%s", ret.c_str() );
9036 }
9037
9038 // Need to do this here because holster_actor::use() checks if/where the item is worn
9039 item &target = *loc.get_item();
9040 if( target.get_use( "holster" ) && !target.contents.empty() ) {
9041 //~ %1$s: weapon name, %2$s: holster name
9042 if( query_yn( pgettext( "holster", "Draw %1$s from %2$s?" ), target.get_contained().tname(),
9043 target.tname() ) ) {
9044 u.invoke_item( &target );
9045 return;
9046 }
9047 }
9048
9049 // Can't use loc.obtain() here because that would cause things to spill.
9050 item to_wield = *loc.get_item();
9051 item_location::type location_type = loc.where();
9052 tripoint pos = loc.position();
9053 int worn_index = INT_MIN;
9054 if( u.is_worn( *loc.get_item() ) ) {
9055 auto ret = u.can_takeoff( *loc.get_item() );
9056 if( !ret.success() ) {
9057 add_msg( m_info, "%s", ret.c_str() );
9058 return;
9059 }
9060 int item_pos = u.get_item_position( loc.get_item() );
9061 if( item_pos != INT_MIN ) {
9062 worn_index = Character::worn_position_to_index( item_pos );
9063 }
9064 }
9065 loc.remove_item();
9066 if( !u.wield( to_wield ) ) {
9067 switch( location_type ) {
9069 // this will not cause things to spill, as it is inside another item
9070 loc = loc.obtain( g->u );
9071 wield( loc );
9072 break;
9074 if( worn_index != INT_MIN ) {
9075 auto it = u.worn.begin();
9076 std::advance( it, worn_index );
9077 u.worn.insert( it, to_wield );
9078 } else {
9079 u.i_add( to_wield );
9080 }
9081 break;
9083 m.add_item( pos, to_wield );
9084 break;
9086 const cata::optional<vpart_reference> vp = g->m.veh_at( pos ).part_with_feature( "CARGO", false );
9087 // If we fail to return the item to the vehicle for some reason, add it to the map instead.
9088 if( !vp || !( vp->vehicle().add_item( vp->part_index(), to_wield ) ) ) {
9089 m.add_item( pos, to_wield );
9090 }
9091 break;
9092 }
9094 debugmsg( "Failed wield from invalid item location" );
9095 break;
9096 }
9097 return;
9098 }
9099}
std::list< item > worn
Definition: character.h:1565
static int worn_position_to_index(int position)
Definition: character.h:1137
item & i_add(item it, bool should_stack=true)
Definition: character.cpp:2305
ret_val< bool > can_unwield(const item &it) const
Check player capable of unwielding an item.
Definition: character.cpp:3068
bool wield(item &target) override
Removes currently wielded item (if any) and replaces it with the target item.
Definition: avatar.cpp:1226
type where() const
Returns the type of location where the item is found.
void remove_item()
Removes the selected item from the game.
tripoint position() const
Returns the position where the item is found.
const item & get_contained() const
Return a contained item (if any and only one).
Definition: item.cpp:6809
item & add_item(const tripoint &p, item new_item)
Place an item on the map, despite the parameter name, this is not necessarily a new item.
Definition: map.cpp:4322
ret_val< bool > can_wield(const item &it) const
Check player capable of wielding an item.
Definition: player.cpp:2534
bool unwield()
Definition: player.cpp:2573
ret_val< bool > can_takeoff(const item &it, const std::list< item > *res=nullptr)
Check player capable of taking off an item.
Definition: player.cpp:2996

References map::add_item(), add_msg(), player::can_takeoff(), Character::can_unwield(), player::can_wield(), item_location::character, item_location::container, item::contents, debugmsg, item_contents::empty(), g, item::get_contained(), item_location::get_item(), Character::get_item_position(), item::get_use(), Character::i_add(), item_location::invalid, avatar::invoke_item(), Character::is_armed(), Character::is_wielding(), Character::is_worn(), m, m_info, item_location::map, Character::martial_arts_data, item_location::obtain(), pgettext(), item_location::position(), query_yn(), item_location::remove_item(), cata::hash64_detail::ret, item::tname(), u, player::unwield(), item_location::vehicle, item_location::where(), wield(), avatar::wield(), Character::worn, and Character::worn_position_to_index().

◆ win()

void game::win ( )

Marks the game as won.

Doesn't end the game.

Definition at line 2732 of file game.cpp.

2733{
2734 win_screen();
2736 memorial().add(
2737 pgettext( "memorial_male", "Closed the portal in %1$.1f days (%2$d seconds)." ),
2738 pgettext( "memorial_female", "Closed the portal in %1$.1f days (%2$d seconds)." ),
2739 to_days<float>( game_duration ), to_seconds<int>( game_duration ) );
2740 if( !u.is_dead_state() ) {
2743 }
2744}
void win_screen()
Definition: game.cpp:2746
void add(const std::string &male_msg, const std::string &female_msg)
Adds an event to the memorial log, to be written to the memorial file when the character dies.
const time_point & start_of_game
Definition: calendar.cpp:34

References achievements_tracker_ptr, memorial_logger::add(), Messages::display_messages(), get_kill_tracker(), player::is_dead_state(), memorial(), pgettext(), show_scores_ui(), calendar::start_of_game, stats(), calendar::turn, u, and win_screen().

◆ win_screen()

void game::win_screen ( )
private

Definition at line 2746 of file game.cpp.

2747{
2748 // TODO: Move this wall somewhere
2750 std::string msg = _( "You managed to close the portal and end the invasion!" );
2751 msg += '\n';
2752 if( u.is_dead_state() ) {
2754 "Unfortunately, you had to sacrifice your life to achieve this." );
2755 msg += colorize( t, c_red ) + '\n';
2756 memorial().add(
2757 pgettext( "memorial_male", "Sacrificed his life to close the portal." ),
2758 pgettext( "memorial_female", "Sacrificed her life to close the portal." ) );
2759 } else {
2760 translation t = translation::to_translation( "win_game", "You managed to survive the ordeal." );
2761 msg += colorize( t, c_green ) + '\n';
2762 memorial().add(
2763 pgettext( "memorial_male", "Safely closed the portal." ),
2764 pgettext( "memorial_female", "Safely closed the portal." ) );
2765 }
2766 msg += string_format( _( "It took you %1$.1f days (%2$d seconds)." ),
2767 to_days<float>( game_duration ), to_seconds<int>( game_duration ) );
2768 // TODO: Print starting stats, traits, skills, all mods ever used, easiest of settings
2769 popup( msg );
2770}
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
static translation to_translation(const std::string &raw)
Store a string, an optional plural form, and an optional context for translation.
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669

References _, memorial_logger::add(), c_green, c_red, colorize(), player::is_dead_state(), memorial(), pgettext(), popup(), calendar::start_of_game, string_format(), translation::to_translation(), calendar::turn, and u.

Referenced by win().

◆ write_memorial_file()

void game::write_memorial_file ( const std::string &  filename,
std::string  sLastWords 
)

Writes information about the character out to a text file timestamped with the time of the file was made.

This serves as a record of the character's state at the time the memorial was made (usually upon death) and accomplishments in a human-readable format.

Definition at line 3135 of file game.cpp.

3136{
3137 const std::string &memorial_dir = PATH_INFO::memorialdir();
3138 const std::string &memorial_active_world_dir = memorial_dir +
3139 world_generator->active_world->world_name + "/";
3140
3141 //Check if both dirs exist. Nested assure_dir_exist fails if the first dir of the nested dir does not exist.
3142 if( !assure_dir_exist( memorial_dir ) ) {
3143 debugmsg( "Could not make '%s' directory", memorial_dir );
3144 return;
3145 }
3146
3147 if( !assure_dir_exist( memorial_active_world_dir ) ) {
3148 debugmsg( "Could not make '%s' directory", memorial_active_world_dir );
3149 return;
3150 }
3151
3152 std::string path = memorial_active_world_dir + filename + ".txt";
3153
3154 write_to_file( path, [&]( std::ostream & fout ) {
3155 memorial().write( fout, sLastWords );
3156 }, _( "player memorial" ) );
3157}
void write(std::ostream &memorial_file, const std::string &epitaph) const
std::string memorialdir()
Definition: path_info.cpp:226

References _, assure_dir_exist(), debugmsg, memorial(), PATH_INFO::memorialdir(), world_generator, memorial_logger::write(), and write_to_file().

Referenced by cleanup_at_end().

◆ zones_manager()

void game::zones_manager ( )

Definition at line 6360 of file game.cpp.

6361{
6362 const tripoint stored_view_offset = u.view_offset;
6363
6365
6366 const int zone_ui_height = 12;
6367 const int zone_options_height = 7;
6368
6369 const int width = 45;
6370
6371 int offsetX = 0;
6372 int max_rows = 0;
6373
6374 catacurses::window w_zones;
6375 catacurses::window w_zones_border;
6376 catacurses::window w_zones_info;
6377 catacurses::window w_zones_info_border;
6378 catacurses::window w_zones_options;
6379
6380 bool show = true;
6381
6382 ui_adaptor ui;
6383 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
6384 if( !show ) {
6385 ui.position( point_zero, point_zero );
6386 return;
6387 }
6388 offsetX = get_option<std::string>( "SIDEBAR_POSITION" ) != "left" ?
6389 TERMX - width : 0;
6390 const int w_zone_height = TERMY - zone_ui_height;
6391 max_rows = w_zone_height - 2;
6392 w_zones = catacurses::newwin( w_zone_height - 2, width - 2,
6393 point( offsetX + 1, 1 ) );
6394 w_zones_border = catacurses::newwin( w_zone_height, width,
6395 point( offsetX, 0 ) );
6396 w_zones_info = catacurses::newwin( zone_ui_height - zone_options_height - 1,
6397 width - 2, point( offsetX + 1, w_zone_height ) );
6398 w_zones_info_border = catacurses::newwin( zone_ui_height, width,
6399 point( offsetX, w_zone_height ) );
6400 w_zones_options = catacurses::newwin( zone_options_height - 1, width - 2,
6401 point( offsetX + 1, TERMY - zone_options_height ) );
6402
6403 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
6404 } );
6405 ui.mark_resize();
6406
6407 std::string action;
6408 input_context ctxt( "ZONES_MANAGER" );
6409 ctxt.register_cardinal();
6410 ctxt.register_action( "CONFIRM" );
6411 ctxt.register_action( "QUIT" );
6412 ctxt.register_action( "ADD_ZONE" );
6413 ctxt.register_action( "REMOVE_ZONE" );
6414 ctxt.register_action( "MOVE_ZONE_UP" );
6415 ctxt.register_action( "MOVE_ZONE_DOWN" );
6416 ctxt.register_action( "SHOW_ZONE_ON_MAP" );
6417 ctxt.register_action( "ENABLE_ZONE" );
6418 ctxt.register_action( "DISABLE_ZONE" );
6419 ctxt.register_action( "SHOW_ALL_ZONES" );
6420 ctxt.register_action( "HELP_KEYBINDINGS" );
6421
6422 auto &mgr = zone_manager::get_manager();
6423 int start_index = 0;
6424 int active_index = 0;
6425 bool blink = false;
6426 bool stuff_changed = false;
6427 bool show_all_zones = false;
6428 int zone_cnt = 0;
6429
6430 // get zones on the same z-level, with distance between player and
6431 // zone center point <= 50 or all zones, if show_all_zones is true
6432 auto get_zones = [&]() {
6433 std::vector<zone_manager::ref_zone_data> zones;
6434 if( show_all_zones ) {
6435 zones = mgr.get_zones();
6436 } else {
6437 const tripoint &u_abs_pos = m.getabs( u.pos() );
6438 for( zone_manager::ref_zone_data &ref : mgr.get_zones() ) {
6439 const tripoint &zone_abs_pos = ref.get().get_center_point();
6440 if( u_abs_pos.z == zone_abs_pos.z && rl_dist( u_abs_pos, zone_abs_pos ) <= 50 ) {
6441 zones.emplace_back( ref );
6442 }
6443 }
6444 }
6445 zone_cnt = static_cast<int>( zones.size() );
6446 return zones;
6447 };
6448
6449 auto zones = get_zones();
6450
6451 auto zones_manager_options = [&]() {
6452 werase( w_zones_options );
6453
6454 if( zone_cnt > 0 ) {
6455 const auto &zone = zones[active_index].get();
6456
6457 if( zone.has_options() ) {
6458 const auto &descriptions = zone.get_options().get_descriptions();
6459
6460 // NOLINTNEXTLINE(cata-use-named-point-constants)
6461 mvwprintz( w_zones_options, point( 1, 0 ), c_white, _( "Options" ) );
6462
6463 int y = 1;
6464 for( const auto &desc : descriptions ) {
6465 mvwprintz( w_zones_options, point( 3, y ), c_white, desc.first );
6466 mvwprintz( w_zones_options, point( 20, y ), c_white, desc.second );
6467 y++;
6468 }
6469 }
6470 }
6471
6472 wnoutrefresh( w_zones_options );
6473 };
6474
6475 cata::optional<tripoint> zone_start;
6476 cata::optional<tripoint> zone_end;
6477 bool zone_blink = false;
6478 bool zone_cursor = false;
6480 zone_start, zone_end, zone_blink, zone_cursor );
6481 add_draw_callback( zone_cb );
6482
6483 auto query_position =
6484 [&]() -> cata::optional<std::pair<tripoint, tripoint>> {
6485 on_out_of_scope invalidate_current_ui( [&]()
6486 {
6487 ui.mark_resize();
6488 } );
6489 restore_on_out_of_scope<bool> show_prev( show );
6490 restore_on_out_of_scope<cata::optional<tripoint>> zone_start_prev( zone_start );
6491 restore_on_out_of_scope<cata::optional<tripoint>> zone_end_prev( zone_end );
6492 show = false;
6493 zone_start = cata::nullopt;
6494 zone_end = cata::nullopt;
6495 ui.mark_resize();
6496
6498 popup.on_top( true );
6499 popup.message( "%s", _( "Select first point." ) );
6500
6502
6503 const look_around_result first = look_around( /*show_window=*/false, center, center, false, true,
6504 false );
6505 if( first.position )
6506 {
6507 popup.message( "%s", _( "Select second point." ) );
6508
6509 const look_around_result second = look_around( /*show_window=*/false, center, *first.position,
6510 true, true, false );
6511 if( second.position ) {
6512 tripoint first_abs = m.getabs( tripoint( std::min( first.position->x,
6513 second.position->x ),
6514 std::min( first.position->y, second.position->y ),
6515 std::min( first.position->z,
6516 second.position->z ) ) );
6517 tripoint second_abs = m.getabs( tripoint( std::max( first.position->x,
6518 second.position->x ),
6519 std::max( first.position->y, second.position->y ),
6520 std::max( first.position->z,
6521 second.position->z ) ) );
6522 return std::pair<tripoint, tripoint>( first_abs, second_abs );
6523 }
6524 }
6525
6526 return cata::nullopt;
6527 };
6528
6529 ui.on_redraw( [&]( const ui_adaptor & ) {
6530 if( !show ) {
6531 return;
6532 }
6533 zones_manager_draw_borders( w_zones_border, w_zones_info_border, zone_ui_height, width );
6534 zones_manager_shortcuts( w_zones_info );
6535
6536 if( zone_cnt == 0 ) {
6537 werase( w_zones );
6538 mvwprintz( w_zones, point( 2, 5 ), c_white, _( "No Zones defined." ) );
6539
6540 } else {
6541 werase( w_zones );
6542
6543 calcStartPos( start_index, active_index, max_rows, zone_cnt );
6544
6545 draw_scrollbar( w_zones_border, active_index, max_rows, zone_cnt, point_south );
6546 wnoutrefresh( w_zones_border );
6547
6548 int iNum = 0;
6549
6550 tripoint player_absolute_pos = m.getabs( u.pos() );
6551
6552 //Display saved zones
6553 for( auto &i : zones ) {
6554 if( iNum >= start_index &&
6555 iNum < start_index + ( ( max_rows > zone_cnt ) ? zone_cnt : max_rows ) ) {
6556 const auto &zone = i.get();
6557
6558 nc_color colorLine = ( zone.get_enabled() ) ? c_white : c_light_gray;
6559
6560 if( iNum == active_index ) {
6561 mvwprintz( w_zones, point( 0, iNum - start_index ), c_yellow, "%s", ">>" );
6562 colorLine = ( zone.get_enabled() ) ? c_light_green : c_green;
6563 }
6564
6565 //Draw Zone name
6566 mvwprintz( w_zones, point( 3, iNum - start_index ), colorLine,
6567 trim_by_length( zone.get_name(), 15 ) );
6568
6569 //Draw Type name
6570 mvwprintz( w_zones, point( 20, iNum - start_index ), colorLine,
6571 mgr.get_name_from_type( zone.get_type() ) );
6572
6573 tripoint center = zone.get_center_point();
6574
6575 //Draw direction + distance
6576 mvwprintz( w_zones, point( 32, iNum - start_index ), colorLine, "%*d %s",
6577 5, static_cast<int>( trig_dist( player_absolute_pos, center ) ),
6578 direction_name_short( direction_from( player_absolute_pos,
6579 center ) ) );
6580
6581 //Draw Vehicle Indicator
6582 mvwprintz( w_zones, point( 41, iNum - start_index ), colorLine,
6583 zone.get_is_vehicle() ? "*" : "" );
6584 }
6585 iNum++;
6586 }
6587
6588 // Display zone options
6589 zones_manager_options();
6590 }
6591
6592 wnoutrefresh( w_zones );
6593 } );
6594
6595 zones_manager_open = true;
6596 do {
6597 if( action == "ADD_ZONE" ) {
6598 do { // not a loop, just for quick bailing out if canceled
6599 const auto maybe_id = mgr.query_type();
6600 if( !maybe_id.has_value() ) {
6601 break;
6602 }
6603
6604 const zone_type_id &id = maybe_id.value();
6605 auto options = zone_options::create( id );
6606
6607 if( !options->query_at_creation() ) {
6608 break;
6609 }
6610
6611 auto default_name = options->get_zone_name_suggestion();
6612 if( default_name.empty() ) {
6613 default_name = mgr.get_name_from_type( id );
6614 }
6615 const auto maybe_name = mgr.query_name( default_name );
6616 if( !maybe_name.has_value() ) {
6617 break;
6618 }
6619 const std::string &name = maybe_name.value();
6620
6621 const auto position = query_position();
6622 if( !position ) {
6623 break;
6624 }
6625
6626 mgr.add( name, id, g->u.get_faction()->id, false, true, position->first,
6627 position->second, options );
6628
6629 zones = get_zones();
6630 active_index = zone_cnt - 1;
6631
6632 stuff_changed = true;
6633 } while( false );
6634
6635 blink = false;
6636 } else if( action == "SHOW_ALL_ZONES" ) {
6637 show_all_zones = !show_all_zones;
6638 zones = get_zones();
6639 active_index = 0;
6640 } else if( zone_cnt > 0 ) {
6641 if( action == "UP" ) {
6642 active_index--;
6643 if( active_index < 0 ) {
6644 active_index = zone_cnt - 1;
6645 }
6646 blink = false;
6647 } else if( action == "DOWN" ) {
6648 active_index++;
6649 if( active_index >= zone_cnt ) {
6650 active_index = 0;
6651 }
6652 blink = false;
6653 } else if( action == "REMOVE_ZONE" ) {
6654 if( active_index < zone_cnt ) {
6655 mgr.remove( zones[active_index] );
6656 zones = get_zones();
6657 active_index--;
6658
6659 if( active_index < 0 ) {
6660 active_index = 0;
6661 }
6662 }
6663 blink = false;
6664 stuff_changed = true;
6665
6666 } else if( action == "CONFIRM" ) {
6667 auto &zone = zones[active_index].get();
6668
6669 uilist as_m;
6670 as_m.text = _( "What do you want to change:" );
6671 as_m.entries.emplace_back( 1, true, '1', _( "Edit name" ) );
6672 as_m.entries.emplace_back( 2, true, '2', _( "Edit type" ) );
6673 as_m.entries.emplace_back( 3, zone.get_options().has_options(), '3',
6674 zone.get_type() == zone_type_id( "LOOT_CUSTOM" ) ? _( "Edit filter" ) : _( "Edit options" ) );
6675 as_m.entries.emplace_back( 4, !zone.get_is_vehicle(), '4', _( "Edit position" ) );
6676 // TODO: Enable moving vzone after vehicle zone can be bigger than 1*1
6677 as_m.entries.emplace_back( 5, !zone.get_is_vehicle(), '5', _( "Move position" ) );
6678 as_m.query();
6679
6680 switch( as_m.ret ) {
6681 case 1:
6682 if( zone.set_name() ) {
6683 stuff_changed = true;
6684 }
6685 break;
6686 case 2:
6687 if( zone.set_type() ) {
6688 stuff_changed = true;
6689 }
6690 break;
6691 case 3:
6692 if( zone.get_options().query() ) {
6693 stuff_changed = true;
6694 }
6695 break;
6696 case 4: {
6697 const auto pos = query_position();
6698 if( pos && ( pos->first != zone.get_start_point() ||
6699 pos->second != zone.get_end_point() ) ) {
6700 zone.set_position( *pos );
6701 stuff_changed = true;
6702 }
6703 break;
6704 }
6705 case 5: {
6706 on_out_of_scope invalidate_current_ui( [&]() {
6707 ui.mark_resize();
6708 } );
6709 restore_on_out_of_scope<bool> show_prev( show );
6710 restore_on_out_of_scope<cata::optional<tripoint>> zone_start_prev( zone_start );
6711 restore_on_out_of_scope<cata::optional<tripoint>> zone_end_prev( zone_end );
6712 show = false;
6713 zone_start = cata::nullopt;
6714 zone_end = cata::nullopt;
6715 ui.mark_resize();
6716 static_popup message_pop;
6717 message_pop.on_top( true );
6718 message_pop.message( "%s", _( "Moving zone." ) );
6719 const auto zone_local_start_point = m.getlocal( zone.get_start_point() );
6720 const auto zone_local_end_point = m.getlocal( zone.get_end_point() );
6721 // local position of the zone center, used to calculate the u.view_offset,
6722 // could center the screen to the position it represents
6723 auto view_center = m.getlocal( zone.get_center_point() );
6724 const look_around_result result_local = look_around( false, view_center,
6725 zone_local_start_point, false, false,
6726 false, true, zone_local_end_point );
6727 if( result_local.position ) {
6728 const auto new_start_point = m.getabs( *result_local.position );
6729 if( new_start_point == zone.get_start_point() ) {
6730 break; // Nothing changed, don't save
6731 }
6732
6733 const auto new_end_point = zone.get_end_point() - zone.get_start_point() + new_start_point;
6734 zone.set_position( std::pair<tripoint, tripoint>( new_start_point, new_end_point ) );
6735 stuff_changed = true;
6736 }
6737 }
6738 break;
6739 default:
6740 break;
6741 }
6742
6743 blink = false;
6744 } else if( action == "MOVE_ZONE_UP" && zone_cnt > 1 ) {
6745 if( active_index < zone_cnt - 1 ) {
6746 mgr.swap( zones[active_index], zones[active_index + 1] );
6747 zones = get_zones();
6748 active_index++;
6749 }
6750 blink = false;
6751 stuff_changed = true;
6752
6753 } else if( action == "MOVE_ZONE_DOWN" && zone_cnt > 1 ) {
6754 if( active_index > 0 ) {
6755 mgr.swap( zones[active_index], zones[active_index - 1] );
6756 zones = get_zones();
6757 active_index--;
6758 }
6759 blink = false;
6760 stuff_changed = true;
6761
6762 } else if( action == "SHOW_ZONE_ON_MAP" ) {
6763 //show zone position on overmap;
6764 tripoint_abs_omt player_overmap_position = u.global_omt_location();
6765 // TODO: fix point types
6766 tripoint_abs_omt zone_overmap( ms_to_omt_copy( zones[active_index].get().get_center_point() ) );
6767
6768 ui::omap::display_zones( player_overmap_position, zone_overmap, active_index );
6769 } else if( action == "ENABLE_ZONE" ) {
6770 zones[active_index].get().set_enabled( true );
6771
6772 stuff_changed = true;
6773
6774 } else if( action == "DISABLE_ZONE" ) {
6775 zones[active_index].get().set_enabled( false );
6776
6777 stuff_changed = true;
6778 }
6779 }
6780
6781 if( zone_cnt > 0 ) {
6782 blink = !blink;
6783 const auto &zone = zones[active_index].get();
6784 zone_start = m.getlocal( zone.get_start_point() );
6785 zone_end = m.getlocal( zone.get_end_point() );
6786 ctxt.set_timeout( BLINK_SPEED );
6787 } else {
6788 blink = false;
6789 zone_start = zone_end = cata::nullopt;
6790 ctxt.reset_timeout();
6791 }
6792
6793 // Actually accessed from the terrain overlay callback `zone_cb` in the
6794 // call to `ui_manager::redraw`.
6795 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6796 zone_blink = blink;
6798
6800
6801 //Wait for input
6802 action = ctxt.handle_input();
6803 } while( action != "QUIT" );
6804 zones_manager_open = false;
6805 ctxt.reset_timeout();
6806 zone_cb = nullptr;
6807
6808 if( stuff_changed ) {
6809 auto &zones = zone_manager::get_manager();
6810 if( query_yn( _( "Save changes?" ) ) ) {
6811 zones.save_zones();
6812 } else {
6813 zones.load_zones();
6814 }
6815
6816 zones.cache_data();
6817 }
6818
6819 u.view_offset = stored_view_offset;
6820}
query_popup & on_top(bool top)
Whether to show the popup on the top of the screen.
Definition: popup.cpp:59
std::reference_wrapper< zone_data > ref_zone_data
Definition: clzones.h:345
static shared_ptr_fast< zone_options > create(const zone_type_id &type)
Definition: clzones.cpp:185
int trig_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:512
static void zones_manager_shortcuts(const catacurses::window &w_info)
Definition: game.cpp:6295
static void zones_manager_draw_borders(const catacurses::window &w_border, const catacurses::window &w_info_border, const int iInfoHeight, const int width)
Definition: game.cpp:6318
std::string options()
Definition: path_info.cpp:238
const std::set< itype_id > & get()
void display_zones(const tripoint_abs_omt &center, const tripoint_abs_omt &select, int iZoneIndex)
Display overmap like with display() and display the given zone.
std::string trim_by_length(const std::string &text, int width)
Definition: output.cpp:224
cata::optional< tripoint > position
Definition: game.h:127

References _, action, add_draw_callback(), BLINK_SPEED, c_green, c_light_gray, c_light_green, c_white, c_yellow, calcStartPos(), center, zone_options::create(), create_zone_callback(), direction_from(), direction_name_short(), ui::omap::display_zones(), draw_scrollbar(), uilist::entries, g, charge_removal_blacklist::get(), zone_manager::get_manager(), map::getabs(), map::getlocal(), Character::global_omt_location(), input_context::handle_input(), invalidate_main_ui_adaptor(), look_around(), m, query_popup::message(), ms_to_omt_copy(), mvwprintz(), om_direction::name(), catacurses::newwin(), cata::nullopt, query_popup::on_top(), PATH_INFO::options(), point_south, point_zero, popup(), Character::pos(), look_around_result::position, uilist::query(), query_yn(), ui_manager::redraw(), input_context::register_action(), input_context::register_cardinal(), input_context::reset_timeout(), uilist::ret, rl_dist(), second, input_context::set_timeout(), TERMX, TERMY, uilist::text, trig_dist(), trim_by_length(), tripoint_zero, u, player::view_offset, catacurses::werase(), catacurses::wnoutrefresh(), tripoint::z, zones_manager_draw_borders(), zones_manager_open, and zones_manager_shortcuts().

Referenced by handle_action().

◆ zoom_in()

void game::zoom_in ( )

Definition at line 7314 of file game.cpp.

7315{
7316#if defined(TILES)
7317 if( tileset_zoom == 64 ) {
7318 tileset_zoom = MAXIMUM_ZOOM_LEVEL;
7319 } else {
7321 }
7322 rescale_tileset( tileset_zoom );
7323#endif
7324}

References tileset_zoom.

Referenced by handle_action(), and look_around().

◆ zoom_out()

void game::zoom_out ( )

Definition at line 7302 of file game.cpp.

7303{
7304#if defined(TILES)
7305 if( tileset_zoom > MAXIMUM_ZOOM_LEVEL ) {
7307 } else {
7308 tileset_zoom = 64;
7309 }
7310 rescale_tileset( tileset_zoom );
7311#endif
7312}

References tileset_zoom.

Referenced by handle_action(), and look_around().

Friends And Related Function Documentation

◆ advanced_inventory

friend class advanced_inventory
friend

Definition at line 146 of file game.h.

◆ Creature_range

friend class Creature_range
friend

Definition at line 360 of file game.h.

Referenced by all_creatures().

◆ editmap

friend class editmap
friend

Definition at line 145 of file game.h.

◆ get_avatar

avatar & get_avatar ( )
friend

Definition at line 100 of file avatar.cpp.

101{
102 return g->u;
103}

◆ get_distribution_grid_tracker

distribution_grid_tracker & get_distribution_grid_tracker ( )
friend

Returns distribution grid tracker that is a part of the global game *g.

game TODO: This wouldn't be required in an ideal world

Definition at line 12581 of file game.cpp.

12582{
12583 return *g->grid_tracker_ptr;
12584}

◆ get_map

map & get_map ( )
friend

Definition at line 141 of file map.cpp.

142{
143 return g->m;
144}

Referenced by extended_description(), and print_terrain_info().

◆ get_player_character

Character & get_player_character ( )
friend

Definition at line 376 of file character.cpp.

377{
378 return g->u;
379}

◆ get_weather

weather_manager & get_weather ( )
friend

Definition at line 64 of file weather.cpp.

65{
66 return *g->weather_manager_ptr;
67}

Referenced by do_turn(), get_player_input(), is_in_sunlight(), load(), natural_light_level(), place_player_overmap(), serialize_master(), setup(), start_game(), and unserialize_master().

◆ main_menu

friend class main_menu
friend

Definition at line 147 of file game.h.

◆ monster_range

friend class monster_range
friend

Definition at line 359 of file game.h.

Referenced by all_monsters().

Member Data Documentation

◆ achievements_tracker_ptr

pimpl<achievements_tracker> game::achievements_tracker_ptr
private

Definition at line 1003 of file game.h.

Referenced by death_screen(), game(), handle_action(), serialize(), setup(), unserialize(), and win().

◆ active_npc

◆ auto_travel_mode

bool game::auto_travel_mode = false

Definition at line 1066 of file game.h.

Referenced by handle_action(), serialize(), and unserialize().

◆ bVMonsterLookFire

bool game::bVMonsterLookFire = false
private

Definition at line 1083 of file game.h.

Referenced by list_monsters(), look_around(), and setup().

◆ coming_to_stairs

std::vector<monster> game::coming_to_stairs

◆ critter_died

bool game::critter_died = false
private

Has anything died in this turn and needs to be cleaned up?

Definition at line 1097 of file game.h.

Referenced by cleanup_dead(), and set_critter_died().

◆ critter_tracker

◆ debug_hour_timer

◆ debug_pathfinding

bool game::debug_pathfinding = false

Definition at line 1047 of file game.h.

◆ debug_submap_grid_overlay

bool game::debug_submap_grid_overlay = false

Definition at line 1048 of file game.h.

◆ destination_preview

std::vector<tripoint> game::destination_preview
private

◆ displaying_lighting_condition

int game::displaying_lighting_condition = 0

Type of lighting condition overlay to display.

Definition at line 1060 of file game.h.

◆ displaying_overlays

cata::optional<action_id> game::displaying_overlays
private

Definition at line 967 of file game.h.

Referenced by display_overlay_state(), and display_toggle_overlay().

◆ displaying_visibility_creature

Creature* game::displaying_visibility_creature

Creature for which to display the visibility map.

Definition at line 1058 of file game.h.

Referenced by display_visibility().

◆ draw_callbacks

std::vector<weak_ptr_fast<draw_callback_t> > game::draw_callbacks
private

Definition at line 251 of file game.h.

Referenced by add_draw_callback(), and draw().

◆ driving_view_offset

point game::driving_view_offset

Definition at line 1045 of file game.h.

Referenced by calc_driving_offset(), do_turn(), handle_action(), and set_driving_view_offset().

◆ event_bus_ptr

pimpl<event_bus> game::event_bus_ptr
private

Definition at line 1001 of file game.h.

Referenced by events().

◆ faction_manager_ptr

◆ first_redraw_since_waiting_started

bool game::first_redraw_since_waiting_started = true
private

Is this the first redraw since waiting (sleeping or activity) started.

Definition at line 1099 of file game.h.

Referenced by do_turn(), and game().

◆ follower_ids

std::set<character_id> game::follower_ids
private

◆ fullscreen

bool game::fullscreen = false

◆ gamemode

std::unique_ptr<special_game> game::gamemode
private

◆ grid_tracker_ptr

pimpl<distribution_grid_tracker> game::grid_tracker_ptr
private

Definition at line 1007 of file game.h.

Referenced by do_turn(), load_map(), on_options_changed(), and update_map().

◆ is_looking

bool game::is_looking = false
private

Definition at line 250 of file game.h.

Referenced by draw_ter(), and look_around().

◆ kill_tracker_ptr

pimpl<kill_tracker> game::kill_tracker_ptr
private

Definition at line 1004 of file game.h.

Referenced by game(), get_kill_tracker(), serialize(), setup(), and unserialize().

◆ last_mouse_edge_scroll

std::chrono::time_point<std::chrono::steady_clock> game::last_mouse_edge_scroll
private

Definition at line 1116 of file game.h.

Referenced by mouse_edge_scrolling().

◆ last_mouse_edge_scroll_vector_overmap

tripoint game::last_mouse_edge_scroll_vector_overmap
private

Definition at line 1118 of file game.h.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ last_mouse_edge_scroll_vector_terrain

tripoint game::last_mouse_edge_scroll_vector_terrain
private

Definition at line 1117 of file game.h.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ last_save_timestamp

time_t game::last_save_timestamp
private

Definition at line 1089 of file game.h.

Referenced by autosave(), init_autosave(), and quicksave().

◆ latest_lightlevels

std::array<float, OVERMAP_LAYERS> game::latest_lightlevels
mutableprivate

Definition at line 1090 of file game.h.

Referenced by natural_light_level(), and reset_light_level().

◆ list_item_downvote

std::string game::list_item_downvote
private

Definition at line 1080 of file game.h.

Referenced by list_items().

◆ list_item_upvote

std::string game::list_item_upvote
private

Definition at line 1079 of file game.h.

Referenced by list_items().

◆ liveview

live_view& game::liveview
private

Definition at line 998 of file game.h.

Referenced by draw_look_around_cursor(), and handle_mouseview().

◆ liveview_ptr

pimpl<live_view> game::liveview_ptr
private

Definition at line 997 of file game.h.

◆ m

map& game::m

Definition at line 1011 of file game.h.

Referenced by autopilot_vehicles(), cata_event_dispatch::avatar_moves(), butcher(), catch_a_monster(), check_near_zone(), check_zone(), control_vehicle(), disable_robot(), disp_NPCs(), do_turn(), draw(), draw_bullet(), draw_critter(), draw_critter_highlighted(), draw_critter_internal(), draw_hit_mon(), draw_look_around_cursor(), draw_ter(), examine(), extended_description(), find_nearby_items(), find_or_make_stairs(), fling_creature(), forced_door_closing(), get_cur_om(), get_dangerous_tile(), get_fishable_locations(), get_levx(), get_levy(), get_levz(), get_player_input(), get_veh_dir_indicator_location(), grabbed_furn_move(), grabbed_veh_move(), handle_action(), is_empty(), is_game_over(), is_in_sunlight(), is_sheltered(), knockback(), list_items(), list_monsters(), load(), load_map(), load_npcs(), look_around(), mon_info_update(), monmove(), moving_vehicle_dismount(), peek(), perhaps_add_random_npc(), phasing_move(), pickup(), place_critter_around(), place_player(), place_player_overmap(), pre_print_all_tile_info(), print_all_tile_info(), print_fields_info(), print_graffiti_info(), print_items_info(), print_terrain_info(), print_trap_info(), process_artifact(), prompt_dangerous_tile(), remoteveh(), save_cyborg(), save_maps(), serialize(), setup(), shift_monsters(), start_game(), start_hauling(), try_get_left_click_action(), try_get_right_click_action(), update_map(), update_stair_monsters(), use_computer(), validate_camps(), validate_linked_vehicles(), validate_mounted_npcs(), vertical_move(), vertical_notes(), vertical_shift(), walk_move(), wield(), and zones_manager().

◆ main_ui_adaptor

weak_ptr_fast<ui_adaptor> game::main_ui_adaptor
private

◆ map_ptr

pimpl<map> game::map_ptr
private

Definition at line 995 of file game.h.

◆ memorial_logger_ptr

pimpl<memorial_logger> game::memorial_logger_ptr
private

Definition at line 1005 of file game.h.

Referenced by game(), and memorial().

◆ monstairz

int game::monstairz = 0

Definition at line 1032 of file game.h.

Referenced by update_stair_monsters(), and vertical_move().

◆ mostseen

int game::mostseen = 0

◆ moves_since_last_save

int game::moves_since_last_save = 0
private

Definition at line 1088 of file game.h.

Referenced by do_turn(), get_moves_since_last_save(), init_autosave(), quickload(), and quicksave().

◆ new_game

bool game::new_game = false

True if the game has just started or loaded, else false.

Definition at line 1028 of file game.h.

Referenced by do_turn(), setup(), and start_game().

◆ next_mission_id

int game::next_mission_id = 0
private

Definition at line 1086 of file game.h.

Referenced by assign_mission_id(), serialize_master(), setup(), and unserialize_master().

◆ next_npc_id

character_id game::next_npc_id
private

Definition at line 1084 of file game.h.

Referenced by assign_npc_id(), serialize_master(), setup(), and unserialize_master().

◆ npcs_dirty

bool game::npcs_dirty = false
private

Has a NPC been spawned since last load?

Definition at line 1095 of file game.h.

Referenced by do_turn(), load_npcs(), and set_npcs_dirty().

◆ queue_screenshot

bool game::queue_screenshot = false

Definition at line 1067 of file game.h.

Referenced by do_turn().

◆ remoteveh_cache

vehicle* game::remoteveh_cache
private

Definition at line 1093 of file game.h.

Referenced by remoteveh(), setremoteveh(), and setup().

◆ remoteveh_cache_time

time_point game::remoteveh_cache_time
private

Definition at line 1092 of file game.h.

Referenced by remoteveh(), setremoteveh(), and setup().

◆ right_sidebar

bool game::right_sidebar = false

Definition at line 1063 of file game.h.

◆ safe_mode

◆ safe_mode_warning_logged

bool game::safe_mode_warning_logged = false
private

Definition at line 1082 of file game.h.

Referenced by check_safe_mode_allowed(), handle_action(), and set_safe_mode().

◆ scen

const scenario* game::scen

Definition at line 1030 of file game.h.

Referenced by start_calendar(), and start_game().

◆ scent

scent_map& game::scent

Definition at line 1013 of file game.h.

Referenced by display_scent(), do_turn(), serialize(), setup(), unserialize(), update_map(), and vertical_shift().

◆ scent_ptr

pimpl<scent_map> game::scent_ptr
private

Definition at line 999 of file game.h.

◆ seed

unsigned int game::seed = 0
private

Seed for all the random numbers that should have consistent randomness (weather).

Definition at line 1111 of file game.h.

Referenced by get_seed(), serialize_master(), start_game(), and unserialize_master().

◆ sFilter

std::string game::sFilter
private

Definition at line 1078 of file game.h.

Referenced by list_items(), and reset_item_list_state().

◆ show_panel_adm

bool game::show_panel_adm = false

Definition at line 1062 of file game.h.

Referenced by draw_panels(), and load_static_data().

◆ spell_events_ptr

pimpl<spell_events> game::spell_events_ptr
private

Definition at line 1006 of file game.h.

Referenced by game(), and spell_events_subscriber().

◆ stats_tracker_ptr

pimpl<stats_tracker> game::stats_tracker_ptr
private

Definition at line 1002 of file game.h.

Referenced by game(), serialize(), stats(), and unserialize().

◆ ter_view_p

tripoint game::ter_view_p

Definition at line 1034 of file game.h.

Referenced by draw(), and draw_ter().

◆ tileset_zoom

int game::tileset_zoom = 0
private

How far the tileset should be zoomed out, 16 is default.

32 is zoomed in by x2, 8 is zoomed out by x0.5

Definition at line 1108 of file game.h.

Referenced by get_zoom(), look_around(), mouse_edge_scrolling_terrain(), reset_zoom(), set_zoom(), zoom_in(), and zoom_out().

◆ timed_event_manager_ptr

pimpl<timed_event_manager> game::timed_event_manager_ptr
private

Definition at line 1000 of file game.h.

◆ timed_events

timed_event_manager& game::timed_events

Definition at line 1014 of file game.h.

Referenced by do_turn(), natural_light_level(), and setup().

◆ token_provider_ptr

pimpl<drop_token_provider> game::token_provider_ptr

Definition at line 1023 of file game.h.

Referenced by serialize(), setup(), and unserialize().

◆ turnssincelastmon

int game::turnssincelastmon = 0

Definition at line 1069 of file game.h.

Referenced by handle_action(), mon_info_update(), and setup().

◆ u

avatar& game::u

Definition at line 1012 of file game.h.

Referenced by add_npc_follower(), autopilot_vehicles(), cata_event_dispatch::avatar_moves(), butcher(), calc_driving_offset(), cancel_activity_or_ignore_query(), cancel_activity_query(), catch_a_monster(), centerlistview(), chat(), check_safe_mode_allowed(), cleanup_at_end(), control_vehicle(), create_starting_npcs(), critter_at(), critter_by_id(), disable_robot(), disp_NPCs(), display_scent(), do_turn(), draw(), draw_critter(), draw_critter_highlighted(), draw_critter_internal(), draw_hit_mon(), draw_line(), draw_look_around_cursor(), draw_minimap(), draw_panels(), draw_ter(), draw_trail_to_square(), draw_veh_dir_indicator(), drop(), drop_in_direction(), exam_vehicle(), examine(), extended_description(), favorite_ammo_or_select(), find_nearby_items(), find_or_make_stairs(), fling_creature(), forced_door_closing(), fungal_effects::fungalize(), get_dangerous_tile(), get_player_base_save_path(), get_player_input(), get_veh_dir_indicator_location(), grabbed_furn_move(), grabbed_move(), grabbed_veh_move(), handle_action(), handle_key_blocking_activity(), inv_map_splice(), inventory_item_menu(), is_game_over(), is_hostile_within(), is_in_viewport(), item_action_menu(), knockback(), list_items(), list_items_monsters(), list_missions(), list_monsters(), load(), look_around(), mon_info(), mon_info_update(), monmove(), move_save_to_graveyard(), moving_vehicle_dismount(), npc_menu(), on_move_effects(), open_consume_item_menu(), open_gate(), overmap_npc_move(), peek(), perhaps_add_random_npc(), phasing_move(), pickup_feet(), place_player(), place_player_overmap(), print_all_tile_info(), print_creature_info(), print_items_info(), print_terrain_info(), print_trap_info(), process_activity(), process_artifact(), process_voluntary_act_interrupt(), prompt_dangerous_tile(), quickload(), reload(), reload_item(), reload_weapon(), reload_wielded(), remoteveh(), remove_npc_follower(), save(), save_player_data(), serialize(), set_driving_view_offset(), setremoteveh(), shared_from(), slip_down(), fungal_effects::spread_fungus_one_tile(), start_game(), start_hauling(), try_get_left_click_action(), try_get_right_click_action(), unload(), unserialize(), update_map(), update_overmap_seen(), update_stair_monsters(), use_computer(), validate_camps(), validate_npc_followers(), vertical_move(), vertical_notes(), vertical_shift(), walk_move(), wield(), win(), win_screen(), and zones_manager().

◆ u_ptr

pimpl<avatar> game::u_ptr
private

Definition at line 996 of file game.h.

◆ u_shared_ptr

shared_ptr_fast<player> game::u_shared_ptr
private

Definition at line 1073 of file game.h.

Referenced by shared_from().

◆ uquit

quit_status game::uquit

Used in main.cpp to determine what type of quit is being performed.

Definition at line 1026 of file game.h.

Referenced by cleanup_at_end(), do_turn(), get_player_input(), handle_action(), is_game_over(), and setup().

◆ user_action_counter

int game::user_action_counter = 0
private

Definition at line 1105 of file game.h.

Referenced by get_user_action_counter(), and handle_action().

◆ w_minimap

catacurses::window game::w_minimap

Definition at line 1038 of file game.h.

Referenced by create_or_get_main_ui_adaptor(), and draw_minimap().

◆ w_minimap_ptr

catacurses::window game::w_minimap_ptr
private

Definition at line 1076 of file game.h.

Referenced by create_or_get_main_ui_adaptor().

◆ w_omlegend

catacurses::window game::w_omlegend

Definition at line 1037 of file game.h.

◆ w_overmap

catacurses::window game::w_overmap

Definition at line 1036 of file game.h.

◆ w_pixel_minimap

catacurses::window game::w_pixel_minimap

◆ w_terrain

◆ w_terrain_ptr

catacurses::window game::w_terrain_ptr
private

Definition at line 1075 of file game.h.

Referenced by create_or_get_main_ui_adaptor().

◆ wait_popup

std::unique_ptr<static_popup> game::wait_popup
private

Definition at line 1124 of file game.h.

Referenced by do_turn().

◆ was_fullscreen

bool game::was_fullscreen = false

Definition at line 1065 of file game.h.

Referenced by load_static_data(), reenter_fullscreen(), and temp_exit_fullscreen().

◆ weather_manager_ptr

pimpl<weather_manager> game::weather_manager_ptr
private

Definition at line 1008 of file game.h.

◆ zones_manager_open

bool game::zones_manager_open = false
private

Is Zone manager open or not - changes graphics of some zone tiles.

Definition at line 1101 of file game.h.

Referenced by is_zones_manager_open(), and zones_manager().


The documentation for this class was generated from the following files: